source: subversion/utils/osm-activity/osm-activity.pl @ 1486

Last change on this file since 1486 was 1486, checked in by nickburch, 13 years ago

Simple, cron friendly script for reporting the number of recent edits done by everyone in an area from the rss feed

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#!/usr/bin/perl
2#
3
4use strict;
5
6my %places = (
7        oxford    => [ 51.752, -1.25794 ],
8        charlbury => [ 51.8726, -1.481 ],
9);
10
11my $place = shift;
12if($place && $place =~ /^\-?\d+\.\d+/) {
13        my $long = shift;
14        my $lat = $place;
15        $place = $lat.",".$long;
16
17        my @ll = ($lat,$long);
18        $places{$place} = \@ll;
19}
20
21unless($place && $places{$place}) {
22        print "Use:\n";
23        print "   osm-activity.pl <place>\n";
24        print "\nWhere place is one of:\n";
25        print "\t".join(", ", keys %places)."\n";
26        exit 1;
27}
28
29# Download the feed
30my $url = "http://www.openstreetmap.org/feeds/nodes.rss?latitude=".$places{$place}->[0]."&longitude=".$places{$place}->[1];
31print "Handling place $place:\n";
32print "  Fetching $url\n";
33
34open(RSS, "wget -q -O - '$url' |");
35
36# Read it
37my $rss;
38while(<RSS>) { $rss .= $_; }
39close RSS;
40
41# Process it
42my @items = ($rss =~ /(<item>.*?<\/item>)/sg);
43my @allusers = ($rss =~ /last edited by (.*?),/sg);
44
45my ($firstedit) = ($items[0] =~ /<pubDate>(.*?)<\/pubDate>/);
46my ($lastedit) = ($items[-1] =~ /<pubDate>(.*?)<\/pubDate>/);
47
48# Get unique users
49my %users;
50foreach my $u (@allusers) {
51        $users{$u}++;
52}
53
54# Report
55print "\n";
56print "There were ".scalar(@items)." edits in the period\n";
57print "There were ".(scalar keys %users)." users active in the period\n";
58print "\n";
59print "The first edit was at $firstedit\n";
60print "The last edit was at $lastedit\n";
61print "\n";
62foreach my $u (sort keys %users) {
63        my $du = $u;
64        while(length($du) lt 50) { $du .= " "; }
65        print "  $du - ".$users{$u}." edits\n";
66}
Note: See TracBrowser for help on using the repository browser.