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.

пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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, count(*) as applications
  36. from applications
  37. where (appeal_status is not null
  38. and appeal_status != 'Unknown')
  39. or status like '%appeal%'
  40. group by authority_name, appeal_status, appeal_decision
  41. collate nocase
  42. ")
  43. apps = ScraperWiki.select("
  44. * from applications
  45. where (appeal_status is not null
  46. and appeal_status != 'Unknown')
  47. or status like '%appeal%'
  48. collate nocase
  49. ")
  50. path = 'appeals'
  51. Petrify.page(path, 'appeals', { summary: summary, apps: apps })
  52. Petrify.csv(path, 'inlink-appeals', apps)
  53. # Media page
  54. stories = CSV.read('media.csv', :headers => true )
  55. Petrify.page('media', 'media', { stories: stories })
  56. # Authority pages
  57. auths = ScraperWiki.select("distinct(authority_name) as authority_name
  58. from applications")
  59. auths.each do |auth|
  60. summary = ScraperWiki.select("
  61. status, decision, appeal_status, appeal_decision, count(*) as qty
  62. from applications
  63. where authority_name = ?
  64. group by status, decision, appeal_status, appeal_decision
  65. ", auth['authority_name'])
  66. apps = ScraperWiki.select("* from applications where authority_name = ?
  67. order by date_received desc", auth['authority_name'])
  68. this_stories = stories.select do |story|
  69. if story['authorities']
  70. story['authorities'].match(auth['authority_name'])
  71. end
  72. end
  73. path = ['authorities', slug(auth['authority_name'])]
  74. Petrify.page(path, 'authority', \
  75. { apps: apps, auth: auth, summary: summary, stories: this_stories })
  76. Petrify.csv(path, slug(auth['authority_name']), apps)
  77. end
  78. end
  79. end