diff options
Diffstat (limited to 'sources')
-rwxr-xr-x | sources/projects/import.rb | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/sources/projects/import.rb b/sources/projects/import.rb index f128281..46ebc60 100755 --- a/sources/projects/import.rb +++ b/sources/projects/import.rb @@ -54,23 +54,33 @@ projects.each do |id, url| http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end - request = Net::HTTP::Get.new(uri.request_uri) - response = http.request(request) begin - last_modified = Time.parse(response['Last-Modified'] || response['Date']).utc.iso8601 + request = Net::HTTP::Get.new(uri.request_uri) + response = http.request(request) + begin + last_modified = Time.parse(response['Last-Modified'] || response['Date']).utc.iso8601 + rescue + last_modified = Time.now.utc + end + db.execute("INSERT INTO projects (id, json_url, last_modified, fetch_date, fetch_status, fetch_json, status, data_updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + id, + url, + last_modified, + Time.now.utc.iso8601, + response.code, + response.body, + (response.code == '200' ? 'OK' : 'FETCH ERROR'), + last_modified + ); rescue - last_modified = Time.now.utc + db.execute("INSERT INTO projects (id, json_url, fetch_date, fetch_status, status) VALUES (?, ?, ?, ?, ?)", + id, + url, + Time.now.utc.iso8601, + 500, + 'FETCH ERROR' + ); end - db.execute("INSERT INTO projects (id, json_url, last_modified, fetch_date, fetch_status, fetch_json, status, data_updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", - id, - url, - last_modified, - Time.now.utc.iso8601, - response.code, - response.body, - (response.code == '200' ? 'OK' : 'FETCH ERROR'), - last_modified - ); end |