From e88b7c52ade6eaf1cba14f91c8b4a2b69348d5ad Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 24 Feb 2015 14:39:41 -0800 Subject: [PATCH] Finessed submit-distances.py --- submit-distances.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/submit-distances.py b/submit-distances.py index 1eb6c38a..dc7d614d 100755 --- a/submit-distances.py +++ b/submit-distances.py @@ -146,19 +146,18 @@ def parse_arguments(): def get_system(argv, tdb): - try: - system = tdb.lookupSystem(argv.origin) - except (KeyError, tradedb.AmbiguityError, LookupError): - system = None - pass - else: - if not argv.allowUpdate: - raise UsageError( - argv, - "System '{}' already exists.\n" - .format(systemName) - ) - if system and argv.detail: + system = tdb.systemByName.get(argv.origin.upper(), None) + if not system: + return argv.origin, None + + if not argv.allowUpdate: + raise UsageError( + argv, + "System '{}' already exists.\n" + .format(systemName) + ) + + if argv.detail: print("EXISTING SYSTEM:", argv.origin) return argv.origin, system @@ -231,17 +230,14 @@ def get_distances(argv, clip, stars): def check_system(argv, tdb, tdbSys, name): - try: - system = tdb.lookupSystem(name) - if not tdbSys: - print("KNOWN SYSTEM") - return - except (tradedb.AmbiguityError, LookupError, KeyError): + system = tdb.systemByName.get(name.upper(), None) + if system and not tdbSys: + print("KNOWN SYSTEM") return - - print("KNOWN SYSTEM: {:.2f} ly".format( - tdbSys.distanceTo(system) - )) + if system: + print("KNOWN SYSTEM: {:.2f} ly".format( + tdbSys.distanceTo(system) + )) def add_extra_stars(argv, extraStars):