Automatically exported from code.google.com/p/planningalerts
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

123 Zeilen
3.5 KiB

  1. #!/usr/local/bin/perl
  2. use strict;
  3. use warnings;
  4. use CGI qw(:cgi);
  5. use HTML::TreeBuilder;
  6. use LWP::UserAgent;
  7. use XML::Writer;
  8. # The master URLs for the East Herts planning search
  9. our $SearchURL = "http://e-services.eastherts.gov.uk/swiftlg/apas/run/WPHAPPCRITERIA";
  10. our $InfoURL = "http://e-services.eastherts.gov.uk/swiftlg/apas/run/WPHAPPDETAIL.DisplayUrl?theApnID=";
  11. our $CommentURL = "http://e-services.eastherts.gov.uk/swiftlg/apas/run/wphmakerep.displayURL?ApnID=";
  12. # We're a CGI script...
  13. my $query = CGI->new();
  14. # Get the date to fetch
  15. my $date = $query->param("day") . "/" . $query->param("month") . "/" . $query->param("year");
  16. # Construct an LWP user agent
  17. our $UA = LWP::UserAgent->new(env_proxy => 1);
  18. # Do the search
  19. my $page = do_post($SearchURL,
  20. {"REGFROMDATE.MAINBODY.WPACIS.1." => $date,
  21. "REGTODATE.MAINBODY.WPACIS.1." => $date,
  22. "SEARCHBUTTON.MAINBODY.WPACIS.1." => "Search"});
  23. # Output an HTTP response header
  24. print $query->header(-type => "text/xml");
  25. # Create an XML output stream
  26. my $Writer = XML::Writer->new(DATA_MODE => 1);
  27. # Output the XML header data
  28. $Writer->xmlDecl("UTF-8");
  29. $Writer->startTag("planning");
  30. $Writer->dataElement("authority_name", "East Herts Council");
  31. $Writer->dataElement("authority_short_name", "East Herts");
  32. $Writer->startTag("applications");
  33. # Output any applications on the first page
  34. output_applications($page);
  35. # Loop over any additional results pages
  36. foreach my $link ($page->look_down("_tag" => "a", "href" => qr/^WPHAPPSEARCHRES\.displayResultsURL/))
  37. {
  38. # Fetch this page...
  39. $page = do_get(URI->new_abs($link->attr("href"), $SearchURL));
  40. # ...and output the applications from it
  41. output_applications($page);
  42. }
  43. # Finish off XML output
  44. $Writer->endTag("applications");
  45. $Writer->endTag("planning");
  46. $Writer->end();
  47. exit 0;
  48. # Make a GET request
  49. sub do_get
  50. {
  51. my $response = $UA->get(@_);
  52. die $response->status_line unless $response->is_success;
  53. return HTML::TreeBuilder->new_from_content($response->content);
  54. }
  55. # Make a POST request
  56. sub do_post
  57. {
  58. my $response = $UA->post(@_);
  59. die $response->status_line unless $response->is_success;
  60. return HTML::TreeBuilder->new_from_content($response->content);
  61. }
  62. # Output applications from a results page
  63. sub output_applications
  64. {
  65. my $page = shift;
  66. # Find the result table
  67. my $table = $page->look_down("_tag" => "table", "cellspacing" => "2", "cellpadding" => "2");
  68. # Process each row of the results
  69. foreach my $row ($table->look_down("_tag" => "tr"))
  70. {
  71. my @cells = $row->look_down("_tag" => "td");
  72. if (@cells >= 3)
  73. {
  74. my $reference = $cells[0]->as_trimmed_text;
  75. my $description = $cells[1]->as_trimmed_text;
  76. my $address = $cells[2]->as_trimmed_text;
  77. my $postcode;
  78. if ($address =~ /\s+([A-Z]+\d+\s+\d+[A-Z]+)$/)
  79. {
  80. $postcode = $1;
  81. }
  82. $Writer->startTag("application");
  83. $Writer->dataElement("council_reference", $reference);
  84. $Writer->dataElement("address", $address);
  85. $Writer->dataElement("postcode", $postcode);
  86. $Writer->dataElement("description", $description);
  87. $Writer->dataElement("info_url", $InfoURL . $reference);
  88. $Writer->dataElement("comment_url", $CommentURL . $reference);
  89. $Writer->dataElement("date_received", $date);
  90. $Writer->endTag("application");
  91. }
  92. }
  93. return;
  94. }