From 87eb6c500e15e0770f25130296d7ea0211e34045 Mon Sep 17 00:00:00 2001 From: "andy@hexten.net" Date: Thu, 19 Mar 2009 23:39:23 +0000 Subject: [PATCH] Allow / as an alternative to in scraper xml response. --- trunk/docs/include/scraper_support.php | 12 ++++++++++++ trunk/docs/templates/about.tpl | 2 +- trunk/tools/application_parser.php | 26 +++++++++++++++++++------- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/trunk/docs/include/scraper_support.php b/trunk/docs/include/scraper_support.php index 82f3e3e..8583c49 100644 --- a/trunk/docs/include/scraper_support.php +++ b/trunk/docs/include/scraper_support.php @@ -308,6 +308,18 @@ function scrape_applications_islington ($search_url, $info_url_base, $comment_ur return array_slice ($matches, 1); } + function location_to_postcode($easting, $northing) { + $url = sprintf( + "http://streetmap.co.uk/streetmap.dll?GridConvert?name=%d,%d&type=OSGrid", + $easting, $northing); + $resp = @file($url); + if (is_array($resp)) $resp = join("\n", $resp); + $resp = strip_tags($resp); + // Kinda ghetto. Would be nice to have a nicer regex for postcodes. + if (preg_match('/Nearest\s+Post\s+Code\s+(\S+\s+\S+)/i', $resp, $mat)) + return $mat[1]; + return NULL; + } function valid_email ($string) { $valid = false; diff --git a/trunk/docs/templates/about.tpl b/trunk/docs/templates/about.tpl index 61f1bed..cb8778b 100644 --- a/trunk/docs/templates/about.tpl +++ b/trunk/docs/templates/about.tpl @@ -2,7 +2,7 @@

You'd probably know if your next door neighbour was going to knock their house down (you'd get a letter through the door telling you they had applied for planning permission and asking you what you thought about it). But you probably never find out if the old cinema or pub 5 streets away is going to be converted into luxury flats until the bulldozers turned up.

- PlanningAlerts.com is a free service built by Richard Pope, Mikel Maron, Sam Smith, Duncan Parkes and Tom Hughes. The site is kindly hosted by mySociety.org. It searches as many local authority planning websites as it can find and emails you details of applications near you. The aim of this to enable shared scrutiny of what is being built (and knocked down) in peoples communities. + PlanningAlerts.com is a free service built by Richard Pope, Mikel Maron, Sam Smith, Duncan Parkes, Tom Hughes and Andy Armstrong. The site is kindly hosted by mySociety.org. It searches as many local authority planning websites as it can find and emails you details of applications near you. The aim of this to enable shared scrutiny of what is being built (and knocked down) in peoples communities.

Planning authorities currently covered by the service

diff --git a/trunk/tools/application_parser.php b/trunk/tools/application_parser.php index beeb96d..98ba2de 100644 --- a/trunk/tools/application_parser.php +++ b/trunk/tools/application_parser.php @@ -148,7 +148,6 @@ } $application->address = $parsed_application->address; - $application->postcode = $parsed_application->postcode; $application->description = $parsed_application->description; $application->info_url = $parsed_application->info_url; $application->comment_url = $parsed_application->comment_url; @@ -164,14 +163,27 @@ $this->store_log("ERROR: Created blank comment tiny url"); } + if (isset($parsed_application->postcode)) { + //Workout the XY location from postcode + $xy = postcode_to_location($parsed_application->postcode); + $application->postcode = $parsed_application->postcode; + $application->x = $xy[0]; + $application->y = $xy[1]; + } + else if (isset($parsed_application->easting) && + isset($parsed_application->northing)) { + $postcode = location_to_postcode( + $parsed_application->easting, + $parsed_application->northing + ); + $application->postcode = $postcode; + $application->x = $parsed_application->easting; + $application->y = $parsed_application->northing; + } + $application->info_tinyurl =$info_tiny_url; $application->comment_tinyurl = $comment_tiny_url; $application->map_url = googlemap_url_from_postcode($application->postcode); - - //Workout the XY location from postcode - $xy = postcode_to_location($application->postcode); - $application->x = $xy[0]; - $application->y = $xy[1]; //Add to array array_push($return_applications, $application); @@ -195,4 +207,4 @@ } -?> \ No newline at end of file +?>