#!/usr/bin/env ruby

require 'scraperwiki'
require 'rest-client'
require 'json'
require 'pp'

morph_api_url = 'https://api.morph.io/adrianshort/inlink-scraper/data.json'

result = RestClient.get(morph_api_url, params: {
  key: ENV['MORPH_API_KEY'],
  query: "select * from applications"
})
  
apps = JSON.parse(result)
ScraperWiki.save_sqlite(['authority_name', 'council_reference'], apps, 'applications')