diff options
author | Ilya Zverev <zverik@textual.ru> | 2016-06-04 14:35:01 +0300 |
---|---|---|
committer | Ilya Zverev <zverik@textual.ru> | 2016-06-04 14:35:01 +0300 |
commit | 114ae064698c5f4c76b0c2df7fe6402b7584c93f (patch) | |
tree | b6a2cfad785b78bb9dc463e451546f3c15af9362 /tools | |
parent | b86735478487d7f9e1784e8a25ee6d259bb6b576 (diff) |
[mwm.py] Universal feature finder
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/python/mwm/find_feature.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/python/mwm/find_feature.py b/tools/python/mwm/find_feature.py new file mode 100755 index 0000000000..4071e7dc08 --- /dev/null +++ b/tools/python/mwm/find_feature.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +import sys, os.path, json +from mwm import MWM + +if len(sys.argv) < 4: + print 'Finds features in an mwm file' + print 'Usage: {0} <country.mwm> <type> <string>'.format(sys.argv[0]) + print 'Type: t for inside types, et for exact type, n for names' + sys.exit(1) + +typ = sys.argv[2].lower() +find = sys.argv[3] + +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(): + found = False + if typ == 'n' and 'name' in feature['header']: + for value in feature['header']['name'].values(): + if find in value: + found = True + elif typ in ('t', 'et'): + for t in feature['header']['types']: + if t == find: + found = True + elif typ == 't' and find in t: + found = True + if found: + print json.dumps(feature, ensure_ascii=False) |