kingborough.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Kingborough Council — Planning Notices (site page, not PlanBuild)
  2. require "nokogiri"
  3. require_relative "../lib/http"
  4. require_relative "../lib/util"
  5. require_relative "../lib/scraper_helpers"
  6. TABLE = ENV.fetch("TABLE_NAME") # run_all.sh sets this from filename: da_kingborough
  7. URL = "https://www.kingborough.tas.gov.au/development/planning-notices/"
  8. DB.ensure_table!(TABLE)
  9. html = Http.get(URL)
  10. doc = Nokogiri::HTML(html)
  11. rows = doc.css("#list tbody tr")
  12. puts "Found #{rows.length} rows for #{TABLE}"
  13. saved = 0
  14. rows.each_with_index do |row, idx|
  15. tds = row.css("td")
  16. next if tds.length < 5
  17. council_reference = tds[0].text.strip
  18. address = tds[1].text.strip
  19. date_received_raw = tds[2].text.strip
  20. on_notice_to_raw = tds[3].text.strip
  21. description = tds[4].text.strip
  22. # All links in the row (often PDFs). Join if there are multiple.
  23. links = row.css("td a").map { |a| abs_url(URL, a["href"]) }.reject(&:empty?)
  24. document_url = links.join(", ")
  25. date_received = Util.parse_aus_date(date_received_raw)
  26. on_notice_to = Util.parse_aus_date(on_notice_to_raw)
  27. # Need a reference and an address to store a row
  28. next if council_reference.empty? || address.empty?
  29. upsert_and_enrich!(
  30. table: TABLE,
  31. row: {
  32. description: description,
  33. date_received: date_received,
  34. date_received_raw: date_received_raw,
  35. address: address,
  36. council_reference: council_reference,
  37. applicant: "",
  38. owner: ""
  39. },
  40. extras: {
  41. document_url: document_url,
  42. on_notice_to: on_notice_to,
  43. on_notice_to_raw: on_notice_to_raw
  44. }
  45. )
  46. saved += 1
  47. end
  48. puts "Done #{TABLE}. Saved #{saved} item(s)."