Automatically exported from code.google.com/p/planningalerts
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Newport.pl 1.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use XML::Writer;
  4. my $file = $ARGV[0];
  5. my $info_url = $ARGV[1];
  6. my $writer = new XML::Writer(DATA_MODE => 1, DATA_INDENT => 2);
  7. $writer->xmlDecl("UTF-8");
  8. $writer->startTag("planning");
  9. $writer->dataElement("authority_name", "Newport City Council");
  10. $writer->dataElement("authority_short_name", "Newport");
  11. $writer->startTag("applications");
  12. open (my $fh, '-|', "pdftotext", "-layout", $file, "-") or die "open failed: $!";
  13. while (my $line = <$fh>) {
  14. if ($line =~ /^\s*App No:\s*(\S+)/) {
  15. my $refno = $1;
  16. my $address = ""; my $proposal = ""; my $date_received;
  17. my $cur_field;
  18. my $near_end;
  19. while (1) {
  20. chomp $line;
  21. $line =~ s/^\s+//; $line =~ s/\s+$//;
  22. if ($line =~ s/^ApplicationSite://) {
  23. $cur_field = \$address;
  24. } elsif ($line =~ s/^Proposal://) {
  25. $cur_field = \$proposal;
  26. } elsif (($line =~ s/^Applicant://) || ($line =~ s/^Agent://) || ($line =~ s/^App Type://)) {
  27. $cur_field = undef;
  28. } elsif ($line =~ /^Date Registered:\s*(\S+)/) {
  29. $date_received = $1;
  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 $near_end && length $line == 1;
  39. $near_end = 1 if $line =~ /^\s*Case Officer:/;
  40. }
  41. my $postcode = "None";
  42. if ($address =~ /([A-Z][A-Z]?\d(\d|[A-Z])? ?\d[A-Z][A-Z])/) {
  43. $postcode = $1;
  44. }
  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", 'planning@newport.gov.uk');
  52. $writer->dataElement("date_received", $date_received);
  53. $writer->endTag;
  54. }
  55. }
  56. $writer->endTag;
  57. $writer->endTag;
  58. $writer->end;