mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
Import JSON data from morph.io via rake task
Usage: MORPH_API_KEY=‘your key’ b rake import_papers:from_morph
This commit is contained in:
parent
f35aa2a9d3
commit
2b4281ad87
2 changed files with 15 additions and 11 deletions
|
@ -1,16 +1,16 @@
|
|||
require 'csv'
|
||||
require 'json'
|
||||
|
||||
class Paper < ActiveRecord::Base
|
||||
class << self
|
||||
def import_from_csv(csv_string)
|
||||
CSV.parse(csv_string, headers: true) do |row|
|
||||
def import_from_json(json_string)
|
||||
JSON.parse(json_string).each do |record|
|
||||
attributes = {
|
||||
name: row['name'],
|
||||
url: row['url'],
|
||||
reference: row['reference'],
|
||||
paper_type: row['paper_type'],
|
||||
originator: row['originator'],
|
||||
published_at: row['published_at'],
|
||||
name: record['name'],
|
||||
url: record['url'],
|
||||
reference: record['reference'],
|
||||
paper_type: record['paper_type'],
|
||||
originator: record['originator'],
|
||||
published_at: record['published_at'],
|
||||
}
|
||||
create!(attributes)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue