| @@ -10,14 +10,40 @@ module UKPlanningScraper | |||||
| } | } | ||||
| options = default_options.merge(options) # The user-supplied options override the defaults | options = default_options.merge(options) # The user-supplied options override the defaults | ||||
| # Validated within the last n days | |||||
| # Assumes that every scraper/system can do a date range search | |||||
| if params[:validated_days] | |||||
| params[:validated_to] = Date.today | |||||
| params[:validated_from] = Date.today - (params[:validated_days] - 1) | |||||
| params[:validated_days].delete | |||||
| end | |||||
| # Received within the last n days | |||||
| # Assumes that every scraper/system can do a date range search | |||||
| if params[:received_days] | |||||
| params[:received_to] = Date.today | |||||
| params[:received_from] = Date.today - (params[:received_days] - 1) | |||||
| params[:received_days].delete | |||||
| end | |||||
| # Decided within the last n days | |||||
| # Assumes that every scraper/system can do a date range search | |||||
| if params[:decided_days] | |||||
| params[:decided_to] = Date.today | |||||
| params[:decided_from] = Date.today - (params[:decided_days] - 1) | |||||
| params[:decided_days].delete | |||||
| end | |||||
| # Select which scraper to use based on the URL | # Select which scraper to use based on the URL | ||||
| if search_url.match(/search\.do\?action=advanced/i) | if search_url.match(/search\.do\?action=advanced/i) | ||||
| return self.scrape_idox(search_url, params, options) | |||||
| apps = self.scrape_idox(search_url, params, options) | |||||
| elsif search_url.match(/generalsearch\.aspx/i) | elsif search_url.match(/generalsearch\.aspx/i) | ||||
| return self.scrape_northgate(search_url, params, options) | |||||
| apps = self.scrape_northgate(search_url, params, options) | |||||
| else | else | ||||
| # Not supported | # Not supported | ||||
| raise "Planning system not supported for URL: #{search_url}" | raise "Planning system not supported for URL: #{search_url}" | ||||
| end | end | ||||
| apps # Single point of successful exit | |||||
| end | end | ||||
| end | end | ||||
| @@ -24,7 +24,10 @@ module UKPlanningScraper | |||||
| form.send(:"date(applicationValidatedStart)", params[:validated_from].strftime("%d/%m/%Y")) if params[:validated_from] | form.send(:"date(applicationValidatedStart)", params[:validated_from].strftime("%d/%m/%Y")) if params[:validated_from] | ||||
| form.send(:"date(applicationValidatedEnd)", params[:validated_to].strftime("%d/%m/%Y")) if params[:validated_to] | form.send(:"date(applicationValidatedEnd)", params[:validated_to].strftime("%d/%m/%Y")) if params[:validated_to] | ||||
| form.send(:"searchCriteria\.description", params[:description]) | |||||
| form.send(:"date(applicationDecisionStart)", params[:decided_from].strftime("%d/%m/%Y")) if params[:decided_from] | |||||
| form.send(:"date(applicationDecisionEnd)", params[:decided_to].strftime("%d/%m/%Y")) if params[:decided_to] | |||||
| form.send(:"searchCriteria\.description", params[:keywords]) | |||||
| # Some councils don't have the applicant name on their form, eg Bexley | # Some councils don't have the applicant name on their form, eg Bexley | ||||
| form.send(:"searchCriteria\.applicantName", params[:applicant_name]) if form.has_field? 'searchCriteria.applicantName' | form.send(:"searchCriteria\.applicantName", params[:applicant_name]) if form.has_field? 'searchCriteria.applicantName' | ||||
| @@ -22,7 +22,7 @@ module UKPlanningScraper | |||||
| 'csbtnSearch' => 'Search' # required | 'csbtnSearch' => 'Search' # required | ||||
| } | } | ||||
| form_vars['txtProposal'] = params[:description] | |||||
| form_vars['txtProposal'] = params[:keywords] | |||||
| # Date received from and to | # Date received from and to | ||||
| if params[:received_from] || params[:received_to] | if params[:received_from] || params[:received_to] | ||||
| @@ -40,6 +40,15 @@ module UKPlanningScraper | |||||
| form_vars['dateEnd'] = params[:validated_to].to_s if params[:validated_to] # YYYY-MM-DD | form_vars['dateEnd'] = params[:validated_to].to_s if params[:validated_to] # YYYY-MM-DD | ||||
| end | end | ||||
| # Date decided from and to | |||||
| if params[:decided_from] || params[:decided_to] | |||||
| form_vars['cboSelectDateValue'] = 'DATE_DECISION' | |||||
| form_vars['rbGroup'] = 'rbRange' | |||||
| form_vars['dateStart'] = params[:decided_from].to_s if params[:decided_from] # YYYY-MM-DD | |||||
| form_vars['dateEnd'] = params[:decided_to].to_s if params[:decided_to] # YYYY-MM-DD | |||||
| end | |||||
| # form_vars.merge!({ 'cboStatusCode' => ENV['MORPH_STATUS']}) if ENV['MORPH_STATUS'] | # form_vars.merge!({ 'cboStatusCode' => ENV['MORPH_STATUS']}) if ENV['MORPH_STATUS'] | ||||
| logger.info "Form variables: #{form_vars.to_s}" | logger.info "Form variables: #{form_vars.to_s}" | ||||