source: subversion/applications/utils/osm-activity/osm-activity.pl @ 4732

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

Add a -h option

  • Property svn:executable set to *
File size: 1.6 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
21my $need_help = 0;
22if($place eq "-h") { $need_help = 1; }
23unless($place && $places{$place}) { $need_help = 1; }
24
25if($need_help) {
26        print "Use:\n";
27        print "   osm-activity.pl <place>\n";
28        print "\nWhere <place> is one of:\n";
29        print "\t".join(", ", keys %places)."\n";
30        print "\nSee README.txt for more information\n";
31        exit 1;
32}
33
34# Download the feed
35my $url = "http://www.openstreetmap.org/feeds/nodes.rss?latitude=".$places{$place}->[0]."&longitude=".$places{$place}->[1];
36print "Handling place $place:\n";
37print "  Fetching $url\n";
38
39open(RSS, "wget -q -O - '$url' |");
40
41# Read it
42my $rss;
43while(<RSS>) { $rss .= $_; }
44close RSS;
45
46# Process it
47my @items = ($rss =~ /(<item>.*?<\/item>)/sg);
48my @allusers = ($rss =~ /last edited by (.*?),/sg);
49
50my ($firstedit) = ($items[0] =~ /<pubDate>(.*?)<\/pubDate>/);
51my ($lastedit) = ($items[-1] =~ /<pubDate>(.*?)<\/pubDate>/);
52
53# Get unique users
54my %users;
55foreach my $u (@allusers) {
56        $users{$u}++;
57}
58
59# Report
60print "\n";
61print "There were ".scalar(@items)." edits in the period\n";
62print "There were ".(scalar keys %users)." users active in the period\n";
63print "\n";
64print "The first edit was at $firstedit\n";
65print "The last edit was at $lastedit\n";
66print "\n";
67foreach my $u (sort keys %users) {
68        my $du = $u;
69        while(length($du) lt 50) { $du .= " "; }
70        print "  $du - ".$users{$u}." edits\n";
71}
Note: See TracBrowser for help on using the repository browser.