[mwm.py] Find feature by id

This commit is contained in:
Ilya Zverev 2016-06-15 11:41:26 +03:00
parent 3dfaae720a
commit 609aac42f4

View file

@ -11,6 +11,7 @@ if len(sys.argv) < 4:
print(' et for exact type ("et shop" won\'t find shop-chemist)')
print(' n for names, case-sensitive ("n Starbucks" for all starbucks)')
print(' m for metadata keys ("m flats" for features with flats)')
print(' id for feature id ("id 1234" for feature #1234)')
sys.exit(1)
typ = sys.argv[2].lower()
@ -19,7 +20,7 @@ find = sys.argv[3].decode('utf-8')
mwm = MWM(open(sys.argv[1], 'rb'))
mwm.read_header()
mwm.read_types(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', 'data', 'types.txt'))
for feature in mwm.iter_features(metadata=True):
for i, feature in enumerate(mwm.iter_features(metadata=True)):
found = False
if typ == 'n' and 'name' in feature['header']:
for value in feature['header']['name'].values():
@ -34,5 +35,7 @@ for feature in mwm.iter_features(metadata=True):
elif typ == 'm' and 'metadata' in feature:
if find in feature['metadata']:
found = True
elif typ == 'id' and i == int(find):
found = True
if found:
print(json.dumps(feature, ensure_ascii=False).encode('utf-8'))