A Ruby gem to get planning applications data from UK council websites.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.5 KiB

  1. require "uk_planning_scraper/version"
  2. require 'uk_planning_scraper/idox'
  3. require 'uk_planning_scraper/northgate'
  4. require 'logger'
  5. module UKPlanningScraper
  6. def self.search(search_url, params, options = {})
  7. default_options = {
  8. delay: 10,
  9. }
  10. options = default_options.merge(options) # The user-supplied options override the defaults
  11. # Validated within the last n days
  12. # Assumes that every scraper/system can do a date range search
  13. if params[:validated_days]
  14. params[:validated_to] = Date.today
  15. params[:validated_from] = Date.today - (params[:validated_days] - 1)
  16. end
  17. # Received within the last n days
  18. # Assumes that every scraper/system can do a date range search
  19. if params[:received_days]
  20. params[:received_to] = Date.today
  21. params[:received_from] = Date.today - (params[:received_days] - 1)
  22. end
  23. # Decided within the last n days
  24. # Assumes that every scraper/system can do a date range search
  25. if params[:decided_days]
  26. params[:decided_to] = Date.today
  27. params[:decided_from] = Date.today - (params[:decided_days] - 1)
  28. end
  29. # Select which scraper to use based on the URL
  30. if search_url.match(/search\.do\?action=advanced/i)
  31. apps = self.scrape_idox(search_url, params, options)
  32. elsif search_url.match(/generalsearch\.aspx/i)
  33. apps = self.scrape_northgate(search_url, params, options)
  34. else
  35. # Not supported
  36. raise "Planning system not supported for URL: #{search_url}"
  37. end
  38. apps # Single point of successful exit
  39. end
  40. end