Ignore:
Timestamp:
Dec 13, 2007, 2:47:39 PM (12 years ago)
Author:
Dominic Hargreaves
Message:

rss

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/perllib/NPEMap/Postcodes.pm

    r549 r597  
    44use warnings;
    55use strict;
     6use XML::RSS;
     7use Date::Format;
    68
    79use vars qw($tt_config);
     
    1214use Chart::Strip;
    1315
     16my $iso8601 = "%Y-%m-%dT%H:%M:%SZ";
     17
    1418require Exporter;
    1519@ISA    = qw(Exporter);
    16 @EXPORT = qw(build_home_stats missing_district_stats build_submission_graph);
     20@EXPORT = qw(build_home_stats missing_district_stats build_submission_graph build_rss);
    1721
    1822sub _getAllStats {
     
    6266    my $num = shift;
    6367    my $sql = <<"HERE";
    64 SELECT easting, northing, ie_easting, ie_northing, outward, inward, TO_CHAR(created_at, 'DDth Mon HH24:MI')AS date
     68SELECT easting, northing, ie_easting, ie_northing, outward, inward, TO_CHAR(created_at, 'DDth Mon HH24:MI')AS date, TO_CHAR(created_at, 'YYYY-MM-DD"T"HH24:MI:SSTZ') AS iso_date
    6569FROM postcodes
    6670WHERE NOT deleted
     
    96100    $template->process('home_stats.tt', $vars, $staticdir . '/stats/summary.html')
    97101        or warn $template->error();
     102}
     103
     104sub build_rss {
     105    my $dbh = shift;
     106    my $template = Template->new($tt_config);
     107
     108    my $lastPostcodes = _getLastPostcodes($dbh, 100);
     109
     110    my $rss = new XML::RSS (version => '1.0');
     111    $rss->channel(
     112        title => 'NPEmap - all postcodes',
     113        link  => 'http://www.npemap.org.uk/',
     114        description => 'All postcodes recently submitted to NPEmap',
     115        dc => {
     116            date => time2str($iso8601, time, "UTC"),
     117            creator => 'webmaster@npemap.org.uk',
     118        },
     119    );
     120
     121    foreach my $postcode (@{$lastPostcodes}) {
     122        my $postcode_text = $postcode->outward . ' ' .
     123                            $postcode->inward || '';
     124        $rss->add_item(
     125            title => $postcode_text,
     126            description => $postcode_text
     127            dc => {
     128                date => $postcode->iso_date
     129            }
     130        );
     131        $rss->save($staticdir . 'allpostcodes.rss');
    98132}
    99133
Note: See TracChangeset for help on using the changeset viewer.