Переглянути джерело

added some perl thingy to make broxborne work

import/raw
memespring 17 роки тому
джерело
коміт
c19ec0239e
2 змінених файлів з 143 додано та 0 видалено
  1. +79
    -0
      trunk/cgi-bin/DateTime/Format/DateParse.pm
  2. +64
    -0
      trunk/cgi-bin/westminster.rb

+ 79
- 0
trunk/cgi-bin/DateTime/Format/DateParse.pm Переглянути файл

@@ -0,0 +1,79 @@
package DateTime::Format::DateParse;

# Copyright (C) 2005-6 Joshua Hoblitt
#
# $Id: DateParse.pm 3517 2006-09-17 23:10:10Z jhoblitt $

use strict;

use vars qw($VERSION);
$VERSION = '0.04';

use DateTime;
use DateTime::TimeZone;
use Date::Parse qw( strptime );
use Time::Zone qw( tz_offset );

sub parse_datetime {
my ($class, $date, $zone) = @_;

# str2time() calls strptime() internally so it's more efficent to use
# strptime() directly. However, the extra validation done by using
# DateTime->new() instad of DateTime->from_epoch() may make it into a net
# loss. In the end, it turns out that strptime()'s offset information is
# needed anyways.
my @t = strptime( $date, $zone );

return undef unless @t;

my ($ss, $mm, $hh, $day, $month, $year, $offset) = @t;

my %p;
if ( $ss ) {
my $fraction = $ss - int( $ss );
$p{ nanosecond } = $fraction * 1e9 if $fraction;
$p{ second } = int $ss;
}
$p{ minute } = $mm if $mm;
$p{ hour } = $hh if $hh;
$p{ day } = $day if $day;
$p{ month } = $month + 1 if $month;
$p{ year } = $year ? $year + 1900 : DateTime->now->year;

# unless there is an explict ZONE, Date::Parse seems to parse date only
# formats, eg. "1995-01-24", as being in the 'local' timezone.
unless ( defined $zone || defined $offset ) {
return DateTime->new(
%p,
time_zone => 'local',
);
}

if ( $zone ) {
if ( DateTime::TimeZone->is_valid_name( $zone ) ) {
return DateTime->new(
%p,
time_zone => $zone,
);
} else {
# attempt to convert Time::Zone tz's into an offset
return DateTime->new(
%p,
time_zone =>
# not an Olson timezone, no DST info
DateTime::TimeZone::offset_as_string( tz_offset( $zone ) ),
);
}
}

return DateTime->new(
%p,
time_zone =>
# not an Olson timezone, no DST info
DateTime::TimeZone::offset_as_string( $offset ),
);
}

1;

__END__

+ 64
- 0
trunk/cgi-bin/westminster.rb Переглянути файл

@@ -0,0 +1,64 @@
#!/opt/local/bin/ruby

description = nil
address = nil
ref = nil
getaddress = false
url = nil

puts '<planning>
<authority_name>City of Westminster</authority_name>
<authority_short_name>Westminster</authority_short_name>
<applications>'

while line = gets
if line.index('Proposal:')
description = line.gsub('<tr><td class="tablefeature">Proposal:</td><td class="tablefeature">','').gsub('</td></tr>','').strip
end

if line.index('<tr><td><a href="currentsearch-details.cfm?CASENO=')
ref = line.gsub('<tr><td><a href="currentsearch-details.cfm?CASENO=','').gsub('</a></td></tr>','').strip
ref = ref[ref.index('>')+1..ref.length]

url = line.gsub('<tr><td><a href="','')
url = url[0, url.index('">')]
end

if getaddress
getaddress = false if line.index('Proposal:')
end

if getaddress
address += line.gsub('</td></tr>','').strip + ' '
end

if line.index('<tr><td class="tablefeature">Address:</td><td class="tablefeature">')
address = line.gsub('<tr><td class="tablefeature">Address:</td><td class="tablefeature">','').strip + ' '
getaddress = true
end

if line.index('</table>') and address
puts '<application>'
puts "<council_reference>#{ref}</council_reference>"
puts "<address>#{address.strip}</address>"
if address
m = address.strip.match(/[A-Z]?[A-Z]\d?\d \d[A-Z][A-Z]/)
if m
puts "<postcode>#{m}</postcode>"
else
puts "<postcode></postcode>"
end
end
puts "<description>#{description}</description>"

puts "<info_url>http://www3.westminster.gov.uk/planningapplications/#{url}</info_url>"
puts "<comment_url></comment_url>"

puts '</application>'

end
end

puts '</applications>'
puts '</planning>'

Завантаження…
Відмінити
Зберегти