X-Git-Url: https://git.nirgal.com/?p=ais.git;a=blobdiff_plain;f=bin%2Fextras%2Feuropa.py;h=dafc735b00fc3e8872916e7344610138cdff8228;hp=ad4c503d804af087547da7826142b58dca0ad029;hb=2206ef83f3264e759e293e0ca4911c58530881d9;hpb=00dc20d33737ea2596d5c01485b2c2ac249088fc diff --git a/bin/extras/europa.py b/bin/extras/europa.py index ad4c503..dafc735 100755 --- a/bin/extras/europa.py +++ b/bin/extras/europa.py @@ -102,13 +102,35 @@ def europa_get(callsign): return result +def normalize_info(info, callsign): + if not info[u'IRCS']: + info[u'IRCS'] = callsign + info[u'Country Code'] = info[u'Country Code'].split(u' - ', 1)[1] + info[u'Port Code'] = info[u'Port Code'].split(u' - ', 1)[1] + info[u'LOA'] = info[u'LOA'].replace(u',', u'.') + info[u'Tonnage GT'] = info[u'Tonnage GT'].replace(u',', u'.').rstrip(' T') + info[u'Main Gear type'] = info[u'Main Gear type'].split(u' - ', 1)[1] + info[u'Secondary Gear type'] = info[u'Secondary Gear type'].split(u' - ', 1)[1] + if info[u'Public aid']: + info[u'Public aid'] = info[u'Public aid'].split(u' - ', 1)[1] + return info + +def myprint(string): + sys.stdout.write(string.encode('utf-8')) + if __name__ == '__main__': from optparse import OptionParser parser = OptionParser(usage='%prog [options] callsign [callsign] ...') parser.add_option('-d', '--debug', action='store_true', dest='debug', default=False, help="debug mode") - parser.add_option('--download-sleep', help="how many seconds do we sleep after each download. default=%default", action='store', type='int', dest='sleep', default=DOWNLOAD_SLEEP_TIME) + parser.add_option('--download-sleep', + action='store', type='int', dest='sleep', default=DOWNLOAD_SLEEP_TIME, + help="how many seconds do we sleep after each download. default=%default") + parser.add_option('--table', + action='store_true', dest='table_format', default=False, + help='Format in table') + (options, args) = parser.parse_args() if len(args) == 0: @@ -136,11 +158,26 @@ if __name__ == '__main__': u'Main Gear type', u'Secondary Gear type', u'External Marking', + u'Public aid', ] + if options.table_format: + for i, key in enumerate(keys): + if i: + myprint(u'\t') + myprint(key) + myprint(u'\n') for callsign in args: info = europa_get(callsign) if not info: continue - for key in keys: - print key, ':', info[key] - print + info = normalize_info(info, callsign) + if options.table_format: + for i, key in enumerate(keys): + if i: + myprint(u'\t') + myprint(info[key]) + myprint(u'\n') + else: + for key in keys: + myprint(key+u': '+info[key]+u'\n') + myprint(u'\n')