Class: MyPreciousPython

Inherits:
Object
  • Object
show all
Defined in:
lib/myprecious_python.rb

Class Method Summary collapse

Class Method Details

.updateObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/myprecious_python.rb', line 7

def self.update
  file = File.new("Packages", "r")

  File.open('dependency-tracking.md', 'w') { |write_file|
    write_file.puts "dependency | Our Version | Latest Version | Date available | Age (in days) | Change Log"
    write_file.puts "--- | --- | --- | --- | --- | ---"
    while (line = file.gets)
      gem_line = line.strip
      name = gem_line.split('==')[0]
      current_version = gem_line.split('==')[1]
      latest_version_string = %x(yolk -U #{name})
      begin
        latest_version = latest_version_string.split(' ')[2].split("(")[1].split(")")[0]
      rescue
        latest_version = current_version
      end
      scrape_url = "https://pypi.python.org/pypi/" + name.to_s + "/" + current_version.to_s
      doc = Nokogiri::HTML(open(scrape_url))
      doc_data = doc.css('tr.odd td')
      if !doc_data.nil?
        current_build_date = doc_data[3].content
      else
        current_build_date = ""
      end

      scrape_url = "https://pypi.python.org/pypi/"+name+"/"+latest_version
      doc = Nokogiri::HTML(open(scrape_url))
      doc_data = doc.css('tr.odd td')
      if !doc_data.nil?
        latest_build_date = doc_data[3].content
      else
        latest_build_date = ""
      end

      begin
        documentation = doc.at('li:contains("Documentation:")').css('a').map { |link| link['href'] }[0]
      rescue Exception => e
        documentation = ""
      end

      begin
        homepage_uri = doc.at('li:contains("Home Page")').text.strip.split("\n").last.strip
      rescue Exception => e
        homepage_uri = ""
      end

      days_complete = Date.parse(latest_build_date) - Date.parse(current_build_date)

      write_file.puts "[" + name + "]" + "(" + homepage_uri.to_s  + ")" + 
                      "|" + current_version.to_s + "|" + latest_version.to_s + "|" +
                      (latest_build_date).to_s + "|" + days_complete.to_i.to_s + "|" +
                      documentation.to_s
    end
    file.close

  }
end