Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exception handling to download of json datasets #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions 2021/download.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# download all json datasets
# download all json datasets to Webget cache



Expand All @@ -11,22 +11,26 @@

def download
## for debugging select some codes
## codes = Factbook.codes.select {|code| ['us', 'au'].include?( code.code ) }
##codes = Factbook.codes.select {|code| ['us', 'au'].include?( code.code ) }

codes = Factbook.codes

i = 0
codes.each do |code|
puts "==> [#{i+1}/#{codes.size}] #{code.format}:"

res = Webget.call( code.data_url ) ## get json dataset / page
if res.status.nok?
puts "!! ERROR - download json call:"
pp res
exit 1
begin ## exception handling as requested in issue #7 -> if one download fails we'll move on to the next one
puts "==> [#{i+1}/#{codes.size}] #{code.format}:"

res = Webget.call( code.data_url ) ## get json dataset / page
if res.status.nok?
puts "!! ERROR - download json call:"
pp res
exit 1
end

i += 1
rescue
puts "!! ERROR - download json call for '%s' failed! -> moving on to the next code " %[code.data_url]
end

i += 1
end
puts "bye"
end
Expand Down