Skip to content

Instantly share code, notes, and snippets.

@universal
Last active May 26, 2016 08:03
Show Gist options
  • Save universal/7c0120f078ab44c1a496b706d9bd1eb7 to your computer and use it in GitHub Desktop.
Save universal/7c0120f078ab44c1a496b706d9bd1eb7 to your computer and use it in GitHub Desktop.
rake read_database
[DEPRECATION] `last_comment` is deprecated. Please use `last_description` instead.
[DEPRECATION] `last_comment` is deprecated. Please use `last_description` instead.
rake aborted!
SyntaxError: /home/ubuntu/workspace/lib/tasks/read_database.rake:22: syntax error, unexpected tLABEL
title: data["artObject"]["title"],
^
/home/ubuntu/workspace/lib/tasks/read_database.rake:23: syntax error, unexpected tLABEL, expecting '='
description: data["artObject"]["description"],
^
/home/ubuntu/workspace/lib/tasks/read_database.rake:24: syntax error, unexpected tLABEL, expecting '='
date: data["artObject"]["dating"]["year"],
^
/home/ubuntu/workspace/lib/tasks/read_database.rake:25: syntax error, unexpected tLABEL, expecting '='
collectie: data["artObject"]["objectCollection"].first,
^
/home/ubuntu/workspace/lib/tasks/read_database.rake:26: syntax error, unexpected tLABEL, expecting '='
colors: data["artObject"]["colors"],
^
/home/ubuntu/workspace/lib/tasks/read_database.rake:27: syntax error, unexpected tLABEL, expecting '='
small_image: data2["levels"].find{ |h| h...
^
/home/ubuntu/workspace/lib/tasks/read_database.rake:27: syntax error, unexpected ')', expecting '}'
/home/ubuntu/workspace/lib/tasks/read_database.rake:37: syntax error, unexpected end-of-input, expecting '}'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:658:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:658:in `block in run_tasks_blocks'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:658:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:658:in `run_tasks_blocks'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/application.rb:452:in `run_tasks_blocks'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:453:in `load_tasks'
/home/ubuntu/workspace/Rakefile:6:in `<top (required)>'
(See full trace by running task with --trace)
desc 'read_database'
task read_database: :environment do
# read all_data
url = "https://www.rijksmuseum.nl/api/nl/collection?key=xxxx&format=json&type=schilderij&toppieces=True"
data = read_data(url)
all_paintings = data["artObjects"]
all_numbers = all_paintings.map { |item| item["objectNumber"] }
# lees alle gegevens
all_numbers.map do |number|
url = "https://www.rijksmuseum.nl/api/nl/collection/NUMBER?key=xxxx&format=json".gsub("NUMBER", number)
data = read_data(url)
# inlezen van de images
url = "https://www.rijksmuseum.nl/api/nl/collection/NUMBER/tiles?key=xxxx&format=json".gsub("NUMBER", number)
data2 = read_data(url)
painting = Painting.find_or_initialize_by( name: data["artObject"]["makers"].first["name"])
attributes = {
title: data["artObject"]["title"],
description: data["artObject"]["description"],
date: data["artObject"]["dating"]["year"],
collectie: data["artObject"]["objectCollection"].first,
colors: data["artObject"]["colors"],
small_image: data2["levels"].find{ |h| h["name"] == "z4" } )
}
painting.update attributes
end
end
def read_data (url)
response = HTTParty.get(url)
return parsed_data = JSON.parse(response.body)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment