Add rake task to import Oparl papers from JSONLine file

This commit is contained in:
Lars Henrik Mai 2020-03-10 11:45:16 +01:00
parent 92f30ebaec
commit 9ce1414b7b

View file

@ -6,3 +6,18 @@ task import_papers: :environment do
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") 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")
Paper.import_from_json(uri.read) Paper.import_from_json(uri.read)
end end
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