Quellcode durchsuchen

Consolidate CSV generator code

main
Adrian Short vor 6 Jahren
Ursprung
Commit
8043a0a899
1 geänderte Dateien mit 12 neuen und 21 gelöschten Zeilen
  1. +12
    -21
      bin/build

+ 12
- 21
bin/build Datei anzeigen

@@ -34,7 +34,13 @@ def write_csv(path_items, filename, data)
FileUtils.mkdir_p(dir)
@log.debug dir
fn = File.join(dir, filename + '.csv')
File.write(fn, data)
csv_string = CSV.generate do |csv|
csv << data.first.keys # header row
data.each { |row| csv << row.values }
end
File.write(fn, csv_string)
@log.info fn
end

@@ -57,22 +63,11 @@ def gen_homepage
write_page('.', 'index', { summary: summary })

# Summary CSV file
csv_string = CSV.generate do |csv|
csv << summary.first.keys # header row
summary.each { |row| csv << row.values }
end

write_csv('.', 'inlink-summary', csv_string)
write_csv('.', 'inlink-summary', summary)

# Full CSV file
apps = ScraperWiki.select("* from applications")
csv_string = CSV.generate do |csv|
csv << apps.first.keys # header row
apps.each { |app| csv << app.values }
end

write_csv('.', 'inlink-full', csv_string)
write_csv('.', 'inlink-full', apps)
end

def gen_new
@@ -96,15 +91,11 @@ def gen_authorities
where authority_name = '#{auth['authority_name']}'
group by status, decision, appeal_status, appeal_decision
")
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 })

csv_string = CSV.generate do |csv|
csv << apps.first.keys # header row
apps.each { |app| csv << app.values }
end
apps = ScraperWiki.select("* from applications where authority_name='#{auth['authority_name']}' order by date_received")

write_csv(['authorities', slug(auth['authority_name'])], slug(auth['authority_name']), csv_string)
write_page(['authorities', slug(auth['authority_name'])], 'authority', { apps: apps, auth: auth, summary: summary })
write_csv(['authorities', slug(auth['authority_name'])], slug(auth['authority_name']), apps)
end
end



Laden…
Abbrechen
Speichern