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.

Glasgow.pl 1.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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", "Glasgow City Council");
  10. $writer->dataElement("authority_short_name", "Glasgow");
  11. $writer->startTag("applications");
  12. open (my $fh, "pdftotext -layout $file -|");
  13. while (my $line = <$fh>) {
  14. if ($line =~ /^\s*Reference:\s*(\S+)/) {
  15. my $refno = $1;
  16. my $address = ""; my $proposal = ""; my $date_received;
  17. my $cur_field;
  18. while (1) {
  19. chomp $line;
  20. $line =~ s/^\s+//; $line =~ s/\s+$//;
  21. if ($line =~ s/^Address://) {
  22. $cur_field = \$address;
  23. } elsif ($line =~ s/^Proposal://) {
  24. $cur_field = \$proposal;
  25. } elsif ($line =~ /^Date Received:\s*(\S+)/) {
  26. $date_received = $1;
  27. $date_received =~ s#\.#/#g;
  28. $cur_field = undef;
  29. }
  30. $line =~ s/^\s+//;
  31. if (defined $cur_field) {
  32. $$cur_field .= " " if $$cur_field ne "";
  33. $$cur_field .= $line;
  34. }
  35. last if $line =~ /Map Reference:/;
  36. last unless defined ($line = <$fh>);
  37. }
  38. my $postcode = "None";
  39. if ($address =~ /([A-Z][A-Z]?\d(\d|[A-Z])? ?\d[A-Z][A-Z])/) {
  40. $postcode = $1;
  41. }
  42. $writer->startTag("application");
  43. $writer->dataElement("council_reference", $refno);
  44. $writer->dataElement("address", $address);
  45. $writer->dataElement("postcode", $postcode);
  46. $writer->dataElement("description", $proposal);
  47. $writer->dataElement("info_url", $info_url);
  48. $writer->dataElement("comment_url", "planning.representations\@drs.glasgow.gov.uk");
  49. $writer->dataElement("date_received", $date_received);
  50. $writer->endTag;
  51. }
  52. }
  53. $writer->endTag;
  54. $writer->endTag;
  55. $writer->end;