Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

105 lines
3.7 KiB

  1. <?php
  2. //
  3. // Scraper for Richmond
  4. // Created by Matt Ford on Tue 2nd September 2008
  5. //
  6. // The script works according to requirements of PlanningAlerts.com
  7. //
  8. //Check a day is set and is valid
  9. $day = (isset($_GET['day']) && !empty($_GET['day']) && $_GET['day'] > 0 && $_GET['day'] < 32) ? $_GET['day'] : 1;
  10. //Check a month is set and is valid
  11. $month = (isset($_GET['month']) && !empty($_GET['month']) && $_GET['month'] > 0 && $_GET['month'] < 13) ? $_GET['month'] : 1;
  12. //Check a year is set and is valid
  13. $year = (isset($_GET['year']) && !empty($_GET['year']) && $_GET['year'] > 2003 && $_GET['year'] <= gmdate('Y')) ? $_GET['year'] : gmdate('Y');
  14. $xml = array( 'name' => 'Richmond',
  15. 'full_name' => 'London Borough of Richmond upon Thames',
  16. 'url' => 'http://www2.richmond.gov.uk/PlanData2/planning_summary.aspx',
  17. 'detail_url' => 'http://www2.richmond.gov.uk/PlanData2/Planning_CaseNo.aspx?strCASENO=',
  18. 'comments' => 'http://forms.richmond.gov.uk/AF3/an/default.aspx/RenderForm/?F.Name=C5aG_poZZFP');
  19. $date = $day.'/'.$month.'/'.$year;
  20. $applications = array();
  21. function fetch_page($url) {
  22. if(!isset($ch)) {
  23. $ch = curl_init();
  24. }
  25. curl_setopt($ch, CURLOPT_URL, $url);
  26. curl_setopt($ch, CURLOPT_HEADER, 0);
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  28. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  29. curl_setopt($ch, CURLOPT_REFERER, $url);
  30. $data = curl_exec($ch);
  31. return $data;
  32. }
  33. function parse_search($date) {
  34. global $applications;
  35. $url = 'http://www2.richmond.gov.uk/PlanData2/planning_summary.aspx?strRecTo='.$date.'&strRecFrom='.$date;
  36. //echo 'Loading page '.$page_no.' of data for '.$date.' URL:'.$url.'<br />';
  37. $data = fetch_page($url);
  38. $data = explode('</table>',$data);
  39. $data = explode('</TABLE>',$data[1]);
  40. foreach($data as $application) {
  41. $application = explode('</tr>',$application);
  42. $detail = explode('</TD>',$application[3]);
  43. list($AppNo,$junk) = explode('<BR>',$detail[0]);
  44. $AppNo = trim(strip_tags($AppNo));
  45. $applications[$AppNo]['AppNo'] = $AppNo;
  46. $applications[$AppNo]['DateRec'] = trim(strip_tags($detail[2]));
  47. $applications[$AppNo]['Info'] = trim(strip_tags($detail[4]));
  48. $Loc = trim(strip_tags($application[1]));
  49. if(substr($Loc,-29) == 'Click here for a location map') {
  50. $Loc = substr($Loc,0,-29);
  51. }
  52. $applications[$AppNo]['Address'] = $Loc;
  53. preg_match("/([A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2})/",$Loc,$PostCode);
  54. if(isset($PostCode[1])) {
  55. $applications[$AppNo]['PostCode'] = $PostCode[1];
  56. } else {
  57. $applications[$AppNo]['PostCode'] = false;
  58. }
  59. if(empty($AppNo)) {
  60. unset($applications[$AppNo]);
  61. }
  62. }
  63. }
  64. parse_search($date);
  65. header("Content-Type: text/xml");
  66. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  67. echo "<planning>\n";
  68. echo "\t<authority_name>".$xml['full_name']."</authority_name>\n";
  69. echo "\t<authority_short_name>".$xml['name']."</authority_short_name>\n";
  70. echo "\t<applications>\n";
  71. foreach($applications as $application) {
  72. echo "\t\t<application>\n";
  73. echo "\t\t\t<council_reference>".$application['AppNo']."</council_reference>\n";
  74. echo "\t\t\t<address>".$application['Address']."</address>\n";
  75. echo "\t\t\t<postcode>".$application['PostCode']."</postcode>\n";
  76. echo "\t\t\t<description><![CDATA[".$application['Info']."]]></description>\n";
  77. echo "\t\t\t<info_url>".$xml['detail_url'].$application['AppNo']."</info_url>\n";
  78. echo "\t\t\t<comment_url>".$xml['comments']."</comment_url>\n";
  79. echo "\t\t\t<date_received>".$application['DateRec']."</date_received>\n";
  80. echo "\t\t</application>\n";
  81. }
  82. echo "\t</applications>\n";
  83. echo "</planning>";
  84. ?>