aboutsummaryrefslogtreecommitdiff
path: root/sources/projects
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2014-08-21 14:51:09 +0200
committerJochen Topf <jochen@topf.org>2014-08-21 14:51:09 +0200
commit329464dfc287de90850b334f147c9d5ab71a4fdb (patch)
treeafa3f170aa73317fbffed9b5fd0fd580b1a1d880 /sources/projects
parent960a39f5937a50b4d999a3fc5e7465412eb377a0 (diff)
downloadtaginfo-329464dfc287de90850b334f147c9d5ab71a4fdb.tar
taginfo-329464dfc287de90850b334f147c9d5ab71a4fdb.tar.gz
Add https support for project files
Diffstat (limited to 'sources/projects')
-rwxr-xr-xsources/projects/import.rb38
1 files changed, 23 insertions, 15 deletions
diff --git a/sources/projects/import.rb b/sources/projects/import.rb
index 820bf02..4004892 100755
--- a/sources/projects/import.rb
+++ b/sources/projects/import.rb
@@ -25,7 +25,8 @@
#
#------------------------------------------------------------------------------
-require 'net/http'
+require 'net/https'
+require 'uri'
require 'sqlite3'
require 'time'
@@ -48,21 +49,28 @@ end
projects.each do |id, url|
puts " #{id} #{url}"
uri = URI(url)
- Net::HTTP.start(uri.host, uri.port) do |http|
- request = Net::HTTP::Get.new(uri)
- response = http.request(request)
- last_modified = Time.parse(response['Last-Modified']).utc.iso8601
- db.execute("INSERT INTO projects (id, json_url, last_modified, fetch_date, fetch_status, fetch_json, fetch_result, data_updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
- id,
- url,
- last_modified,
- Time.now.utc.iso8601,
- response.code,
- response.body,
- (response.code == '200' ? 'OK' : 'FETCH ERROR'),
- last_modified
- );
+ http = Net::HTTP.new(uri.host, uri.port)
+ if uri.scheme == 'https'
+ 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
+ rescue
+ last_modified = Time.now.utc
+ end
+ db.execute("INSERT INTO projects (id, json_url, last_modified, fetch_date, fetch_status, fetch_json, fetch_result, data_updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+ id,
+ url,
+ last_modified,
+ Time.now.utc.iso8601,
+ response.code,
+ response.body,
+ (response.code == '200' ? 'OK' : 'FETCH ERROR'),
+ last_modified
+ );
end