Basic
[osm-diff.git] / osm-diff.py
blobcc1ff2267d59831ba7b38bfc7cb05b4b8a2f865f
1 #! /usr/bin/python
3 import optparse, urllib2, xml.dom.minidom
5 parser = optparse.OptionParser()
6 parser.add_option("-n", "--node")
8 (options, args) = parser.parse_args()
10 url = "http://openstreetmap.com/api/0.5/node/%s/history" % options.node
12 data = urllib2.urlopen(url).read()
13 history = xml.dom.minidom.parseString(data)
15 history = history.childNodes[0]
16 assert history.nodeName == 'osm'
18 # FIXME make general
19 changes = sorted(history.getElementsByTagName('node'), key=lambda x: x.attributes['timestamp'].value)
21 last_node = changes[0]
23 print "This node was created by %s on %s" % (last_node.attributes['user'].value, last_node.attributes['timestamp'].value)
25 for this_node in changes[1:]:
27 print "On %s user %s..." % (this_node.attributes['timestamp'].value, this_node.attributes['user'].value)
29 # change in location
30 last_loc = (last_node.attributes['lat'].value, last_node.attributes['lon'].value)
31 this_loc = (this_node.attributes['lat'].value, this_node.attributes['lon'].value)
32 if last_loc != this_loc:
33 print "\tchanged the location to %s (old location %s)" % (last_loc, this_loc)
35 last_tags = dict((x.attributes['k'].value, x.attributes['v'].value) for x in last_node.getElementsByTagName('tag'))
36 this_tags = dict((x.attributes['k'].value, x.attributes['v'].value) for x in this_node.getElementsByTagName('tag'))
38 # look at tags that have been added
39 for tag in sorted(this_tags):
40 if tag not in last_tags:
41 print "\tadded tag %s=%s" % (tag, this_tags[tag])
43 for tag in sorted(last_tags):
44 if tag not in this_tags:
45 print "\tdeleted tag %s=%s" % (tag, last_tags[tag])
46 elif last_tags[tag] != this_tags[tag]:
47 print "\tchanged tag %s from %s=%s to %s=%s" % (tag, tag,last_tags[tag], tag, this_tags[tag])
50 last_node = this_node