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:
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')