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.
 
 
 
 
 
 

67 lines
2.0 KiB

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use XML::Writer;
  4. use Date::Parse;
  5. use POSIX;
  6. my $file = $ARGV[0];
  7. my $info_url = $ARGV[1];
  8. my $writer = new XML::Writer(DATA_MODE => 1, DATA_INDENT => 2);
  9. $writer->xmlDecl("UTF-8");
  10. $writer->startTag("planning");
  11. $writer->dataElement("authority_name", "North Ayrshire Council");
  12. $writer->dataElement("authority_short_name", "North Ayrshire");
  13. $writer->startTag("applications");
  14. open (my $fh, '-|', "pdftotext", "-layout", $file, "-") or die "open failed: $!";
  15. while (my $line = <$fh>) {
  16. if ($line =~ /^\s*Application No:\s*(\S+)/) {
  17. my $refno = $1;
  18. my $address = ""; my $proposal = ""; my $date_received = "";
  19. my $cur_field;
  20. while (1) {
  21. chomp $line;
  22. $line =~ s/^\s+//; $line =~ s/\s+$//;
  23. if ($line =~ s/^Location://) {
  24. $cur_field = \$address;
  25. } elsif ($line =~ s/^Description://) {
  26. $cur_field = \$proposal;
  27. } elsif ($line =~ s/^Date Registered://) {
  28. $cur_field = \$date_received;
  29. } elsif (($line =~ s/^Applicant://) || ($line =~ s/^Agent://) || ($line =~ s/^Ward://)) {
  30. $cur_field = undef;
  31. }
  32. $line =~ s/^\s+//;
  33. if (defined $cur_field) {
  34. $$cur_field .= " " if $$cur_field ne "" and $line ne "";
  35. $$cur_field .= $line;
  36. }
  37. last unless defined ($line = <$fh>);
  38. last if $line =~ /^\s*application:/;
  39. }
  40. my $postcode = "None";
  41. if ($address =~ /([A-Z][A-Z]?\d(\d|[A-Z])? ?\d[A-Z][A-Z])/) {
  42. $postcode = $1;
  43. }
  44. my $norm_date_received = strftime("%d/%m/%Y", map { defined $_ ? $_ : 0 } strptime($date_received));
  45. $writer->startTag("application");
  46. $writer->dataElement("council_reference", $refno);
  47. $writer->dataElement("address", $address);
  48. $writer->dataElement("postcode", $postcode);
  49. $writer->dataElement("description", $proposal);
  50. $writer->dataElement("info_url", $info_url);
  51. $writer->dataElement("comment_url", 'dcontrol@north-ayrshire.gov.uk');
  52. $writer->dataElement("date_received", $norm_date_received);
  53. $writer->endTag;
  54. }
  55. }
  56. $writer->endTag;
  57. $writer->endTag;
  58. $writer->end;