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

Last change on this file since 478 was 478, checked in by Dominic Hargreaves, 13 years ago

Add ignore function

  • Property svn:executable set to *
File size: 3.0 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, s.name AS source_name
26FROM     bad_postcodes AS b INNER JOIN postcodes AS p ON (b.postcode = p.id)
27         INNER JOIN sources AS s ON (p.source = s.id)
28WHERE    not b.actioned   $postcode_where
29ORDER BY p.id, b.created_at
30EOF
31
32my $sth = $dbh->prepare($sql);
33$sth->execute or die $dbh->errstr;
34
35if ($sth->rows == 0) {
36    print "No problems\n";
37    exit 0;
38}
39
40# Build up a list of allowed IDs to delete
41my %probids;
42
43my $hr;
44while ($hr = $sth->fetchrow_hashref) {
45    $probids{$hr->{'id'}}++;
46    $hr->{'reporter_email'} = 'anon' unless $hr->{'reporter_email'};
47    $hr->{'prob_ip'} = 'unknown IP' unless $hr->{'prob_ip'};
48    $hr->{'sub_ip'} = '' unless $hr->{'sub_ip'};
49    print $hr->{'id'} . ': ' . $hr->{'outward'} . ' ' . $hr->{'inward'} . ': ';
50    print "by " . $hr->{'reporter_email'};
51    print " at " . $hr->{'prob_ip'};
52    print ' (SAME IP)' if ($hr->{'prob_ip'} eq $hr->{'sub_ip'});
53    print "\n";
54    print " ";
55    print "Reason: " . $hr->{'reason'} . ' ' if $hr->{'reason'};
56    print "(". $hr->{'prob_date'} . ")\n";
57    print " http://www.npemap.org.uk/tiles/map.html#" .
58        int($hr->{'easting'} / 1000) . ',' . int($hr->{'northing'} / 1000) . ",1\n";
59    print " Source: " . $hr->{'source_name'} . "\n";
60}
61
62my $delsth = $dbh->prepare("UPDATE postcodes SET deleted = 't', delete_reason = 1 WHERE id = ?");
63my $actionsth = $dbh->prepare("UPDATE bad_postcodes SET actioned = 't' WHERE postcode = ?");
64my $updsth = $dbh->prepare("UPDATE postcodes SET outward = ?, inward = ? WHERE id = ?");
65
66# Now prompt for deletions
67
68print "Warning: no validation of postcodes input here\n";
69while (1) {
70    unless (%probids) {
71        print "No more problems.\n";
72        last;
73    }
74    print "ID to resolve? (^C to exit): ";
75    my $input = <STDIN>;
76    chomp $input;
77    if ($probids{$input}) {
78        print "d for delete, i to ignore, comma separated postcode to update: ";
79        my $input2 = <STDIN>;
80        chomp $input2;
81        if ($input2 =~ /^d$/i) {
82            $delsth->execute($input) or warn $dbh->errstr;
83        } elsif ($input2 =~ /^i$/i) {
84            # Nothing. We'll mark it as actioned below
85        } elsif ($input2 =~ /(\w*),(\w*)/) {
86            $updsth->execute($1, $2, $input) or warn $dbh->errstr;
87        } else {
88            print "invalid input\n";
89            next;
90        }
91        $actionsth->execute($input) or warn $dbh->errstr;
92        delete $probids{$input};
93    } else {
94        print "$input is not a valid deletion candidate.\n";
95    }
96}
97
98$dbh->disconnect;
Note: See TracBrowser for help on using the repository browser.