Last active
July 13, 2017 20:28
-
-
Save KrzaQ/7e881e3c5fceb0c8f0cc9874b2ce4a7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_data(n) | |
fn = 'g8/%s' % n | |
if File.exist? fn | |
File.read fn | |
else | |
link = 'http://gynvael.coldwind.pl/misja008_drone_io/scans/%s' % n | |
begin | |
b = Time.now | |
Thread.current[:c] = HTTPClient.new unless Thread.current[:c] | |
body = Thread.current[:c].get_content link | |
a = Time.now | |
if a - b > 0.1 | |
puts 'Downloading %s took %.03fs' % [link, a-b] | |
end | |
rescue => e | |
puts 'Download failed: %s' % e | |
retry | |
end | |
File.write fn, body | |
body | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment