source: trunk/npemap.org.uk/scripts/report-foreign-deletions @ 690

Last change on this file since 690 was 690, checked in by Dominic Hargreaves, 12 years ago

first stab at problem reporting

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/usr/bin/perl
2#
3# Copyright (c) 2006-2009 Dominic Hargreaves
4# Permission is hereby granted, free of charge, to any person obtaining a
5# copy of this software and associated documentation files (the "Software"),
6# to deal in the Software without restriction, including without limitation
7# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8# and/or sell copies of the Software, and to permit persons to whom the
9# Software is furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21#
22use strict;
23use warnings;
24
25use FindBin;
26use AppConfig qw(:argcount :expand);
27use MIME::Lite;
28
29# Find our private perl libraries
30use lib "$FindBin::Bin/../perllib";
31use NPEMap;
32use NPEMap::Config;
33
34# Get the postcodes
35my $dbh = setup_dbh() or die $!;
36
37my $sql = <<EOF;
38SELECT id,outward||' '||inward AS postcode,easting,northing,ie_easting,ie_northing,reason from postcodes p inner join bad_postcodes b on (p.id=b.postcode) where source=? and delete_reason=1 and deleted='t' order by id;
39EOF
40
41my $sth = $dbh->prepare($sql);
42
43my $source_sth = $dbh->prepare('SELECT id,name,contact FROM sources WHERE contact IS NOT NULL');
44$source_sth->execute or die $dbh->errstr;
45
46my $source;
47while ($source = $source_sth->fetchrow_hashref) {
48    $sth->execute($source->{id});
49   
50    my @problems = @{$sth->fetchall_arrayref};
51
52        if (@problems) {
53
54        my $body = <<EOF;
55Some postcodes that we got from
56$source->{name}
57have been reported as bad on npemap.org.uk:
58
59NPEmap ID,postcode,easting,northing,ie_easting_ie_northing,reason
60EOF
61
62        $body .= join ',', @{$_} foreach (@problems);
63
64        my $msg = MIME::Lite->new(
65            From    => $adminemail,
66            To      => $source->{contact},
67            Subject => 'Problem postcodes reported on npemap.org.uk',
68            Data    => $body
69        );
70        $msg->send;
71
72
73$dbh->disconnect;
Note: See TracBrowser for help on using the repository browser.