mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
Add method to import Oparl docs to Paper
This commit is contained in:
parent
7a68ef0f26
commit
92f30ebaec
3 changed files with 76 additions and 0 deletions
|
@ -97,6 +97,22 @@ class Paper < ActiveRecord::Base
|
|||
puts "Imported #{count - old_count} Papers!"
|
||||
end
|
||||
|
||||
def import_from_oparl(oparl_doc)
|
||||
doc = JSON.parse(oparl_doc)
|
||||
attributes = {
|
||||
name: doc['name'],
|
||||
body: doc['body'],
|
||||
paper_type: doc['paperType'],
|
||||
reference: doc['reference'],
|
||||
url: doc['web'],
|
||||
published_at: doc['modified'],
|
||||
content: 'n.a.',
|
||||
originator: doc['leipzig:originator']
|
||||
}
|
||||
record = find_or_initialize_by(url: attributes[:url])
|
||||
record.update(attributes) ? record : nil
|
||||
end
|
||||
|
||||
# use DSL to define search queries
|
||||
# see https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl
|
||||
# and https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-rails/lib/rails/templates
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue