From cca68e95c30300cea1cb455ad2ae07c64ac5cce2 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Sat, 26 Oct 2019 23:38:31 +0100 Subject: [PATCH] Generate local JSON file for all applications --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- lib/site.rb | 5 +++++ views/layout.haml | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 0cd25bc..3ea67cb 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,6 @@ source 'https://rubygems.org' ruby '>=2.3' gem 'scraperwiki', :git => 'https://github.com/openaustralia/scraperwiki-ruby/', :branch => 'morph_defaults' -gem 'petrify' +gem 'petrify', '>= 0.4.0' gem 'rest-client' gem 'json' diff --git a/Gemfile.lock b/Gemfile.lock index 627be86..cd85b9a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,7 +12,7 @@ GEM specs: domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) - haml (5.0.4) + haml (5.1.2) temple (>= 0.8.0) tilt http-cookie (1.0.3) @@ -23,7 +23,7 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) netrc (0.11.0) - petrify (0.3.1) + petrify (0.4.0) haml (~> 5.0) rest-client (2.0.2) http-cookie (>= 1.0.2, < 2.0) @@ -32,8 +32,8 @@ GEM sqlite3 (1.3.13) sqlite_magic (0.0.6) sqlite3 - temple (0.8.0) - tilt (2.0.8) + temple (0.8.2) + tilt (2.0.10) unf (0.1.4) unf_ext unf_ext (0.0.7.5) @@ -43,7 +43,7 @@ PLATFORMS DEPENDENCIES json - petrify + petrify (>= 0.4.0) rest-client scraperwiki! diff --git a/lib/site.rb b/lib/site.rb index 230bc60..41e18d7 100644 --- a/lib/site.rb +++ b/lib/site.rb @@ -1,6 +1,7 @@ require 'scraperwiki' require 'petrify' require 'csv' +require 'json' class Site def self.generate @@ -25,6 +26,10 @@ class Site { summary: summary, last_updated: last_updated }) Petrify.csv(path, 'inlink-summary', summary) + # Generate a JSON file with all the data + apps = ScraperWiki.select("* from applications") + Petrify.file(path, 'data.json', apps.to_json) + # New applications page apps = ScraperWiki.select("* from `applications` order by date_received desc limit 60") diff --git a/views/layout.haml b/views/layout.haml index cc1c6f3..164c854 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -42,7 +42,7 @@ Source code %a{ :href => 'https://www.adrianshort.org/tags/inlinkuk/'}< InLink blog posts - %a{ :href => 'https://git.adrianshort.org/data.json'}< + %a{ :href => '/data.json'}< JSON bulk download %a{ :href => 'https://twitter.com/search?f=tweets&vertical=default&q=%23inlink'}< \#InLink on Twitter