Planning applications tracker for InLinkUK from BT kiosks. https://kiosks.adrianshort.org/
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

73 рядки
2.4 KiB

  1. require 'scraperwiki'
  2. require 'petrify'
  3. class Site
  4. def self.generate
  5. # Home page
  6. summary = ScraperWiki.select("
  7. authority_name, status, decision, appeal_status, appeal_decision, count(*) as applications
  8. from applications
  9. group by authority_name, status, decision, appeal_status, appeal_decision
  10. ")
  11. q = ScraperWiki.select("
  12. scraped_at
  13. from applications
  14. order by scraped_at desc
  15. limit 1")
  16. last_updated = DateTime.parse(q[0]['scraped_at'])
  17. path = '.'
  18. Petrify.page(path, 'index', { summary: summary, last_updated: last_updated })
  19. Petrify.csv(path, 'inlink-summary', summary)
  20. # New applications page
  21. apps = ScraperWiki.select("* from `applications` order by date_received desc limit 60")
  22. Petrify.page('new-applications', 'new-applications', { apps: apps })
  23. # Latest decisions page
  24. apps = ScraperWiki.select("* from `applications` order by date_decision desc limit 60")
  25. path = 'decisions'
  26. Petrify.page(path, 'decisions', { apps: apps })
  27. Petrify.csv(path, 'inlink-decisions', apps)
  28. # Appeals page
  29. summary = ScraperWiki.select("
  30. authority_name, appeal_status, appeal_decision, count(*) as applications
  31. from applications
  32. where appeal_status is not null
  33. and appeal_status != 'Unknown'
  34. group by authority_name, appeal_status, appeal_decision
  35. ")
  36. apps = ScraperWiki.select("
  37. * from applications
  38. where appeal_status is not null
  39. and appeal_status != 'Unknown'
  40. ")
  41. path = 'appeals'
  42. Petrify.page(path, 'appeals', { summary: summary, apps: apps })
  43. Petrify.csv(path, 'inlink-appeals', apps)
  44. # Authority pages
  45. auths = ScraperWiki.select("distinct(authority_name) as authority_name from applications")
  46. auths.each do |auth|
  47. summary = ScraperWiki.select("
  48. status, decision, appeal_status, appeal_decision, count(*) as qty
  49. from applications
  50. where authority_name = ?
  51. group by status, decision, appeal_status, appeal_decision
  52. ", auth['authority_name'])
  53. apps = ScraperWiki.select("* from applications where authority_name = ? order by date_received desc", auth['authority_name'])
  54. path = ['authorities', slug(auth['authority_name'])]
  55. Petrify.page(path, 'authority', { apps: apps, auth: auth, summary: summary })
  56. Petrify.csv(path, slug(auth['authority_name']), apps)
  57. end
  58. end
  59. end