source: trunk/npemap.org.uk/scripts/process-problems @ 325

Last change on this file since 325 was 325, checked in by Nick Burch, 15 years ago

Optionally, limit to just working on one postcode

  • Property svn:executable set to *
File size: 2.3 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use FindBin;
7
8# Find our private perl libraries
9use lib "$FindBin::Bin/../perllib";
10use NPEMap;
11
12# Optionally, limit by the postcode ID
13my $postcode_id = shift;
14my $postcode_where = "";
15if($postcode_id && $postcode_id =~ /^\d+$/) {
16        $postcode_where = " AND p.id = $postcode_id ";
17}
18
19# Get the postcodes
20my $dbh = setup_dbh() or die $!;
21
22my $sql = <<EOF;
23SELECT   p.id, outward, inward, p.ip AS sub_ip, b.ip AS prob_ip, b.reason,
24         reporter_email, p.created_at AS sub_date, b.created_at AS prob_date,
25         p.easting, p.northing
26FROM     bad_postcodes AS b INNER JOIN postcodes AS p ON (b.postcode = p.id)
27WHERE    not b.actioned   $postcode_where
28ORDER BY p.id, b.created_at
29EOF
30
31my $sth = $dbh->prepare($sql);
32$sth->execute or die $dbh->errstr;
33
34if ($sth->rows == 0) {
35    print "No problems\n";
36    exit 0;
37}
38
39# Build up a list of allowed IDs to delete
40my %probids;
41
42my $hr;
43while ($hr = $sth->fetchrow_hashref) {
44    $probids{$hr->{'id'}}++;
45    $hr->{'reporter_email'} = 'anon' unless $hr->{'reporter_email'};
46    $hr->{'prob_ip'} = 'unknown IP' unless $hr->{'prob_ip'};
47    $hr->{'sub_ip'} = '' unless $hr->{'sub_ip'};
48    print $hr->{'id'} . ': ' . $hr->{'outward'} . ' ' . $hr->{'inward'} . ': ';
49    print "by " . $hr->{'reporter_email'};
50    print " at " . $hr->{'prob_ip'};
51    print ' (SAME IP)' if ($hr->{'prob_ip'} eq $hr->{'sub_ip'});
52    print "\n";
53    print " ";
54    print "Reason: " . $hr->{'reason'} . ' ' if $hr->{'reason'};
55    print "(". $hr->{'prob_date'} . ")\n";
56    print " http://www.npemap.org.uk/tiles/map.html#" .
57        int($hr->{'easting'} / 1000) . ',' . int($hr->{'northing'} / 1000) . ",1\n";
58}
59
60my $del1sth = $dbh->prepare("UPDATE postcodes SET deleted = 't', delete_reason = 1 WHERE id = ?");
61my $del2sth = $dbh->prepare("UPDATE bad_postcodes SET actioned = 't' WHERE postcode = ?");
62
63# Now prompt for deletions
64while (1) {
65    unless (%probids) {
66        print "No more problems.\n";
67        last;
68    }
69    print "Resolve problem by deleting (^C to exit): ";
70    my $input = <STDIN>;
71    chomp $input;
72    if ($probids{$input}) {
73        $del1sth->execute($input) or warn $dbh->errstr;
74        $del2sth->execute($input) or warn $dbh->errstr;
75        delete $probids{$input};
76    } else {
77        print "$input is not a valid deletion candidate.\n";
78    }
79}
80
81$dbh->disconnect;
Note: See TracBrowser for help on using the repository browser.