Planning applications tracker for InLinkUK from BT kiosks. https://kiosks.adrianshort.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

96 line
2.9 KiB

  1. require 'scraperwiki'
  2. require 'petrify'
  3. require 'csv'
  4. class Site
  5. def self.generate
  6. # Home page
  7. summary = ScraperWiki.select("
  8. authority_name, status, decision, appeal_status, appeal_decision,
  9. count(*) as applications
  10. from applications
  11. group by authority_name, status, decision, appeal_status, appeal_decision
  12. ")
  13. q = ScraperWiki.select("
  14. scraped_at
  15. from applications
  16. order by scraped_at desc
  17. limit 1")
  18. last_updated = DateTime.parse(q[0]['scraped_at'])
  19. path = '.'
  20. Petrify.page(path, 'index', \
  21. { summary: summary, last_updated: last_updated })
  22. Petrify.csv(path, 'inlink-summary', summary)
  23. # New applications page
  24. apps = ScraperWiki.select("* from `applications`
  25. order by date_received desc limit 60")
  26. Petrify.page('new-applications', 'new-applications', { apps: apps })
  27. # Latest decisions page
  28. apps = ScraperWiki.select("* from `applications`
  29. order by date_decision desc limit 60")
  30. path = 'decisions'
  31. Petrify.page(path, 'decisions', { apps: apps })
  32. Petrify.csv(path, 'inlink-decisions', apps)
  33. # Appeals page
  34. summary = ScraperWiki.select("
  35. authority_name, status, decision, appeal_status, appeal_decision,
  36. count(*) as applications
  37. from applications
  38. where (appeal_status is not null
  39. and appeal_status != 'Unknown')
  40. or status like '%appeal%'
  41. group by authority_name, appeal_status, appeal_decision
  42. collate nocase
  43. ")
  44. apps = ScraperWiki.select("
  45. * from applications
  46. where (appeal_status is not null
  47. and appeal_status != 'Unknown')
  48. or status like '%appeal%'
  49. collate nocase
  50. ")
  51. path = 'appeals'
  52. Petrify.page(path, 'appeals', { summary: summary, apps: apps })
  53. Petrify.csv(path, 'inlink-appeals', apps)
  54. # Media page
  55. stories = CSV.read('media.csv', :headers => true )
  56. Petrify.page('media', 'media', { stories: stories })
  57. # Authority pages
  58. auths = ScraperWiki.select("distinct(authority_name) as authority_name
  59. from applications")
  60. auths.each do |auth|
  61. summary = ScraperWiki.select("
  62. status, decision, appeal_status, appeal_decision, count(*) as qty
  63. from applications
  64. where authority_name = ?
  65. group by status, decision, appeal_status, appeal_decision
  66. ", auth['authority_name'])
  67. apps = ScraperWiki.select("* from applications where authority_name = ?
  68. order by date_received desc", auth['authority_name'])
  69. this_stories = stories.select do |story|
  70. if story['authorities']
  71. story['authorities'].match(auth['authority_name'])
  72. end
  73. end
  74. path = ['authorities', slug(auth['authority_name'])]
  75. Petrify.page(path, 'authority', \
  76. { apps: apps, auth: auth, summary: summary, stories: this_stories })
  77. Petrify.csv(path, slug(auth['authority_name']), apps)
  78. end
  79. end
  80. end