Skip to content

Instantly share code, notes, and snippets.

@KrzaQ
Last active July 13, 2017 20:28
Show Gist options
  • Save KrzaQ/7e881e3c5fceb0c8f0cc9874b2ce4a7c to your computer and use it in GitHub Desktop.
Save KrzaQ/7e881e3c5fceb0c8f0cc9874b2ce4a7c to your computer and use it in GitHub Desktop.
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