Automatically exported from code.google.com/p/planningalerts
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

Brentwood.pl 1.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 $date = $ARGV[2];
  7. my $writer = new XML::Writer(DATA_MODE => 1, DATA_INDENT => 2);
  8. $writer->xmlDecl("UTF-8");
  9. $writer->startTag("planning");
  10. $writer->dataElement("authority_name", "Brentwood Borough Council");
  11. $writer->dataElement("authority_short_name", "Brentwood");
  12. $writer->startTag("applications");
  13. open (my $fh, "pdftotext -layout $file -|");
  14. while (my $line = <$fh>) {
  15. chomp $line;
  16. $line =~ s/ //g;
  17. if ($line =~ /Address:/) {
  18. my $ofs_col2 = $-[0];
  19. my $refno = substr $line, 0, $ofs_col2;
  20. $refno =~ s/ +$//g;
  21. my $address = ""; my $proposal = "";
  22. my $cur_field;
  23. while (1) {
  24. if (length($line) > $ofs_col2) {
  25. my $col2 = substr $line, $ofs_col2;
  26. $col2 =~ s/^ +//;
  27. if ($col2 =~ s/^((A?d)?d)?ress://) {
  28. $cur_field = \$address;
  29. } elsif ($col2 =~ s/^((P?r)?o)?posal://) {
  30. $cur_field = \$proposal;
  31. } elsif ($col2 =~ s/^((A?p)?p)?licant://) {
  32. $cur_field = undef;
  33. } elsif ($col2 =~ s/^((A?g)?e)?nt://) {
  34. $cur_field = undef;
  35. }
  36. $col2 =~ s/^ +//; $col2 =~ s/ +$//;
  37. if (defined $cur_field) {
  38. $$cur_field .= " " if $$cur_field ne "";
  39. $$cur_field .= $col2;
  40. }
  41. }
  42. last unless defined ($line = <$fh>);
  43. chomp $line;
  44. $line =~ s/ //g;
  45. last if length $line == 0;
  46. }
  47. my $postcode = "None";
  48. if ($address =~ /([A-Z][A-Z]?\d(\d|[A-Z])? ?\d[A-Z][A-Z])/) {
  49. $postcode = $1;
  50. }
  51. $writer->startTag("application");
  52. $writer->dataElement("council_reference", $refno);
  53. $writer->dataElement("address", $address);
  54. $writer->dataElement("postcode", $postcode);
  55. $writer->dataElement("description", $proposal);
  56. $writer->dataElement("info_url", $info_url);
  57. $writer->dataElement("comment_url", "planning\@brentwood.gov.uk");
  58. $writer->dataElement("date_received", $date);
  59. $writer->endTag;
  60. }
  61. }
  62. $writer->endTag;
  63. $writer->endTag;
  64. $writer->end;