mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-01-22 13:37:58 +01:00
Add rake task to import Oparl papers from JSONLine file
This commit is contained in:
parent
92f30ebaec
commit
9ce1414b7b
1 changed files with 15 additions and 0 deletions
|
@ -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")
|
||||
Paper.import_from_json(uri.read)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue