2015-07-27 22:57:32 +02:00
|
|
|
desc 'Import Paper records from setup importers'
|
|
|
|
task import_papers: :environment do
|
|
|
|
require 'open-uri'
|
2016-03-05 21:24:04 +01:00
|
|
|
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
2020-03-09 14:55:53 +01:00
|
|
|
api_key = Rails.application.config_for(:morph)['key']
|
2016-04-03 08:01:08 +02:00
|
|
|
uri = URI.parse("https://api.morph.io/jrlover/city_council_leipzig_recent_papers/data.json?key=#{api_key}&query=select%20*%20from%20%27data%27")
|
2015-11-09 21:35:32 +01:00
|
|
|
Paper.import_from_json(uri.read)
|
2015-04-13 22:09:28 +02:00
|
|
|
end
|
2020-03-10 11:45:16 +01:00
|
|
|
|
|
|
|
desc 'Import Paper records from Oparl documents in JSONLine format from IMPORT_PATH=(path/to/file)'
|
|
|
|
task import_oparl: :environment do
|
|
|
|
path = ENV['IMPORT_PATH']
|
|
|
|
count = 0
|
|
|
|
errors = 0
|
|
|
|
before = Paper.count
|
|
|
|
File.foreach(path) do |line|
|
|
|
|
result = Paper.import_from_oparl(line)
|
|
|
|
errors +=1 if result.nil?
|
|
|
|
count += 1
|
|
|
|
end
|
|
|
|
after = Paper.count
|
|
|
|
puts "Total: #{count} Success: #{count - errors} Errors: #{errors} New: #{after - before}"
|
|
|
|
end
|