Planning applications tracker for InLinkUK from BT kiosks. https://kiosks.adrianshort.org/
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

92 lignes
2.8 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, 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 \
  69. { |story| story['authorities'].match(auth['authority_name']) }
  70. path = ['authorities', slug(auth['authority_name'])]
  71. Petrify.page(path, 'authority', \
  72. { apps: apps, auth: auth, summary: summary, stories: this_stories })
  73. Petrify.csv(path, slug(auth['authority_name']), apps)
  74. end
  75. end
  76. end