diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb index ecf2fe6..1e15da7 100644 --- a/app/controllers/import_controller.rb +++ b/app/controllers/import_controller.rb @@ -5,9 +5,13 @@ class ImportController < ApplicationController def new_papers_callback require 'open-uri' - api_key = Rails.application.config_for(:morph)['key'] - 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) + #api_key = Rails.application.config_for(:morph)['key'] + #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") + print("before parse") + uri = URI.parse("https://joergreichert.de/srm/input.json") + print("after parse") + #Paper.import_from_json(uri.read) + print("after import") render nothing: true end end diff --git a/app/models/paper.rb b/app/models/paper.rb index 94fdf86..8d87131 100644 --- a/app/models/paper.rb +++ b/app/models/paper.rb @@ -92,7 +92,10 @@ class Paper < ActiveRecord::Base url: record['url'] } record = find_or_initialize_by(url: attributes[:url]) - record.update_attributes(attributes) + out = record.update_attributes(attributes) + if !out + puts "Not imported #{attributes[:name]}: #{record.errors.messages}" + end end puts "Imported #{count - old_count} Papers!" end diff --git a/lib/tasks/import_papers.rake b/lib/tasks/import_papers.rake index f096b76..250197a 100644 --- a/lib/tasks/import_papers.rake +++ b/lib/tasks/import_papers.rake @@ -1,8 +1,8 @@ desc 'Import Paper records from setup importers' task import_papers: :environment do require 'open-uri' - OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE - api_key = Rails.application.config_for(:morph)['key'] - 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") + #OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE + #api_key = Rails.application.config_for(:morph)['key'] + uri = URI.parse("https://joergreichert.de/srm/input.json") Paper.import_from_json(uri.read) end