From 0160286120002ce2f1cffc9b1339179159040187 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Tue, 16 Oct 2018 13:23:44 +0100 Subject: [PATCH] Use chained scrape parameters --- Gemfile | 2 +- Gemfile.lock | 8 ++++---- scraper.rb | 11 ++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 286a1f5..4cee4bf 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,5 @@ source "https://rubygems.org" ruby "2.3.1" -gem "uk_planning_scraper", git: "https://github.com/adrianshort/uk_planning_scraper.git", ref: "8a070e1" +gem "uk_planning_scraper", git: "https://github.com/adrianshort/uk_planning_scraper.git", ref: "cad5fcd" gem "scraperwiki", git: "https://github.com/openaustralia/scraperwiki-ruby.git", branch: "morph_defaults" diff --git a/Gemfile.lock b/Gemfile.lock index 5835e2f..9125ef7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ GIT remote: https://github.com/adrianshort/uk_planning_scraper.git - revision: 8a070e17732b3304e7e73a81cb7538795fe604c0 - ref: 8a070e1 + revision: cad5fcd2b98260572dccf0a4cf1ddfeabc469a43 + ref: cad5fcd specs: - uk_planning_scraper (0.2.0) + uk_planning_scraper (0.4.0) http mechanize (~> 2.7) @@ -24,7 +24,7 @@ GEM connection_pool (2.2.2) domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) - http (3.3.0) + http (4.0.0) addressable (~> 2.3) http-cookie (~> 1.0) http-form_data (~> 2.0) diff --git a/scraper.rb b/scraper.rb index 81c80f9..3dfcee5 100644 --- a/scraper.rb +++ b/scraper.rb @@ -3,16 +3,13 @@ require 'scraperwiki' auths = UKPlanningScraper::Authority.tagged('london') -scrapes = [ - { validated_days: ENV['MORPH_DAYS'].to_i }, - { decided_days: ENV['MORPH_DAYS'].to_i } -] +params = %w(validated_days decided_days) auths.each_with_index do |auth, i| - scrapes.each_with_index do |scrape, j| - puts "Authority #{i + 1} of #{auths.size}: Scrape #{j + 1} of #{scrapes.size} for #{auth.name}." + params.each_with_index do |param, j| + puts "Authority #{i + 1} of #{auths.size}: Scrape #{j + 1} of #{params.size} for #{auth.name}." begin - apps = auth.scrape(scrape) + apps = auth.send(param, ENV['MORPH_DAYS'].to_i).scrape ScraperWiki.save_sqlite([:authority_name, :council_reference], apps) puts "#{auth.name}: #{apps.size} application(s) saved." rescue StandardError => e