Class: Gsrd::Download
- Inherits:
-
Object
- Object
- Gsrd::Download
- Defined in:
- lib/gsrd.rb
Instance Method Summary collapse
- #go ⇒ Object
-
#initialize(token) ⇒ Download
constructor
A new instance of Download.
Constructor Details
#initialize(token) ⇒ Download
Returns a new instance of Download.
25 26 27 |
# File 'lib/gsrd.rb', line 25 def initialize(token) @token = token end |
Instance Method Details
#go ⇒ Object
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 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gsrd.rb', line 29 def go() @time = Time.new @month = @time.month.to_s.rjust(2, "0") @day = @time.day.to_s.rjust(2, "0") @directory_name = Dir.pwd + "/gsrd-downloads-#{@time.year}-#{@month}-#{@day}" Dir.mkdir(@directory_name) unless File.exists?(@directory_name) @pagination = 1 @count = 0 loop do response = HTTParty.get($repos_uri + @token + $page + "#{@pagination}") for repo in response.parsed_response @uri = repo["html_url"] @download_uri = @uri + $archive + repo["default_branch"] + $extension @file_name = repo["owner"]["login"] + "-" + repo["name"] + "-" + repo["default_branch"] + $extension puts "\n\n======= DOWNLOADING " + repo["name"] + " ======= " puts "URL: " + @uri puts "Download URL: " + @download_uri puts "started: " + Time.now.strftime("%d/%m/%Y %H:%M:%S") @wget = "wget -O " + @directory_name + "/" + @file_name + " " + @download_uri + " -q --show-progress" `#{@wget}` puts "finished: " + Time.now.strftime("%d/%m/%Y %H:%M:%S") @count += 1 end @pagination += 1 break if response.parsed_response.count == 0 end puts "\n\n======= #{@count} repos were downloaded to gsrd-downloads directory =======\n\n" end |