|
@@ -4,6 +4,7 @@ require 'scraperwiki' |
|
|
require 'haml' |
|
|
require 'haml' |
|
|
require 'pp' |
|
|
require 'pp' |
|
|
require 'logger' |
|
|
require 'logger' |
|
|
|
|
|
require 'csv' |
|
|
require_relative '../lib/helpers' |
|
|
require_relative '../lib/helpers' |
|
|
|
|
|
|
|
|
OUTPUT_DIR = '_site' |
|
|
OUTPUT_DIR = '_site' |
|
@@ -28,6 +29,15 @@ def write_page(path_items, template, locals = {}) |
|
|
# https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 |
|
|
# https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def write_csv(path_items, filename, data) |
|
|
|
|
|
dir = File.join(OUTPUT_DIR, path_items) |
|
|
|
|
|
FileUtils.mkdir_p(dir) |
|
|
|
|
|
@log.debug dir |
|
|
|
|
|
fn = File.join(dir, filename + '.csv') |
|
|
|
|
|
File.write(fn, data) |
|
|
|
|
|
@log.info fn |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
def create_output_dir |
|
|
def create_output_dir |
|
|
# Recursively delete working directory to ensure no redundant files are left behind from previous builds. |
|
|
# Recursively delete working directory to ensure no redundant files are left behind from previous builds. |
|
|
# FileUtils.rm_rf(@working_dir) |
|
|
# FileUtils.rm_rf(@working_dir) |
|
@@ -56,6 +66,13 @@ def gen_authorities |
|
|
") |
|
|
") |
|
|
apps = ScraperWiki.select("* from applications where authority_name='#{auth['authority_name']}' order by date_received") |
|
|
apps = ScraperWiki.select("* from applications where authority_name='#{auth['authority_name']}' order by date_received") |
|
|
write_page(['authorities', slug(auth['authority_name'])], 'authority', { apps: apps, auth: auth, summary: summary }) |
|
|
write_page(['authorities', slug(auth['authority_name'])], 'authority', { apps: apps, auth: auth, summary: summary }) |
|
|
|
|
|
|
|
|
|
|
|
csv_string = CSV.generate do |csv| |
|
|
|
|
|
csv << apps.first.keys # header row |
|
|
|
|
|
apps.each { |app| csv << app.values } |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
write_csv(['authorities', slug(auth['authority_name'])], slug(auth['authority_name']), csv_string) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|