Automatically exported from code.google.com/p/planningalerts
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

101 satır
4.0 KiB

  1. <?php
  2. //
  3. // Scraper for Wiltshire
  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. $authority = array( 'name' => 'Wiltshire',
  15. 'full_name' => 'Wiltshire County Council',
  16. 'url' => 'http://www.wiltshireplanningapplications.co.uk/planning_summary.aspx',
  17. 'detail_url' => 'http://www.wiltshireplanningapplications.co.uk/Planning_DETAIL.aspx?strCASENO=',
  18. 'comments' => 'planningcontrol@wiltshire.gov.uk');
  19. // There is a comment url available on some of the info pages, but we would
  20. // have to download the info page to get it (it has a case officer parameter).
  21. // The page looks like it might work without the case officer parameter, but
  22. // the email address is probably a better bet - Duncan
  23. $date = $day.'/'.$month.'/'.$year;
  24. $applications = array();
  25. function fetch_page($url) {
  26. if(!isset($ch)) {
  27. $ch = curl_init();
  28. }
  29. curl_setopt($ch, CURLOPT_URL, $url);
  30. curl_setopt($ch, CURLOPT_HEADER, 0);
  31. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  33. curl_setopt($ch, CURLOPT_REFERER, $url);
  34. $data = curl_exec($ch);
  35. return $data;
  36. }
  37. function parse_search($date) {
  38. global $applications,$authority;
  39. $url = $authority['url'].'?strRecTo='.$date.'&strRecFrom='.$date;
  40. //echo 'Loading page '.$page_no.' of data for '.$date.' URL:'.$url.'<br />';
  41. $data = fetch_page($url);
  42. $data = explode('</table>',$data);
  43. $data = explode('</TABLE>',$data[2]);
  44. foreach($data as $application) {
  45. $application = explode('</tr>',$application);
  46. $detail = explode('</TD>',$application[1]);
  47. list($AppNo,$junk) = explode('<BR>',$detail[0]);
  48. $AppNo = trim(strip_tags($AppNo));
  49. $applications[$AppNo]['AppNo'] = $AppNo;
  50. $applications[$AppNo]['Info'] = trim(strip_tags($application[2]));
  51. list($Loc,$junk) = explode('</a>',$detail[2]);
  52. $Loc = trim(strip_tags($Loc));
  53. $applications[$AppNo]['Address'] = $Loc;
  54. list($junk,$DateRec) = explode('</td>',$detail[2]);
  55. $applications[$AppNo]['DateRec'] = trim(strip_tags($DateRec));
  56. preg_match("/([A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2})/",$Loc,$PostCode);
  57. if(isset($PostCode[1])) {
  58. $applications[$AppNo]['PostCode'] = $PostCode[1];
  59. } else {
  60. $applications[$AppNo]['PostCode'] = false;
  61. }
  62. if(empty($AppNo)) {
  63. unset($applications[$AppNo]);
  64. }
  65. }
  66. }
  67. parse_search($date);
  68. header("Content-Type: text/xml");
  69. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  70. echo "<planning>\n";
  71. echo "\t<authority_name>".$authority['full_name']."</authority_name>\n";
  72. echo "\t<authority_short_name>".$authority['name']."</authority_short_name>\n";
  73. echo "\t<applications>\n";
  74. foreach($applications as $application) {
  75. echo "\t\t<application>\n";
  76. echo "\t\t\t<council_reference>".$application['AppNo']."</council_reference>\n";
  77. echo "\t\t\t<address>".$application['Address']."</address>\n";
  78. echo "\t\t\t<postcode>".$application['PostCode']."</postcode>\n";
  79. echo "\t\t\t<description><![CDATA[".$application['Info']."]]></description>\n";
  80. echo "\t\t\t<info_url>".$authority['detail_url'].$application['AppNo']."</info_url>\n";
  81. echo "\t\t\t<comment_url>".$authority['comments']."</comment_url>\n";
  82. echo "\t\t\t<date_received>".$application['DateRec']."</date_received>\n";
  83. echo "\t\t</application>\n";
  84. }
  85. echo "\t</applications>\n";
  86. echo "</planning>";
  87. ?>