#!/usr/bin/python

from imposm.parser import OSMParser
from string import find
from sys import argv

class MaxspeedFinder(object):
	maxspeed = 0
	maxspeed_any = 0;
	def ways(self, ways):
		for osmid, tags, refs in ways:
			found = 0
			found_any = 0
			for k, v in tags.iteritems():
				if find(k, "maxspeed") > -1:
					self.maxspeed_any += 1
					found_any += 1
				if k == "maxspeed":
					self.maxspeed += 1
					found = 1

# items where maxspeed is missing, but *maxspeed* exists
#			if found == 0 and found_any:

# items where maxspeed is exists and additional *maxspeed* exists too
			if found != found_any:
				print "=== %010d ===" % osmid
				for k, v in tags.iteritems():
					if find(k, "maxspeed") > -1:
						print "%s, %s" % (k, v.encode('utf-8'))

counter = MaxspeedFinder()
p = OSMParser(concurrency = 4, ways_callback = counter.ways)
p.parse(argv[1])

print "=================="
print "maxspeed:", counter.maxspeed
print "*maxspeed*",counter.maxspeed_any
