diff --git a/lib/tasks/import_papers.rake b/lib/tasks/import_papers.rake index f096b76..a3ba139 100644 --- a/lib/tasks/import_papers.rake +++ b/lib/tasks/import_papers.rake @@ -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