From 19e8cbfdffdb932879faee01b8b7d851eff08eb9 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sun, 8 Mar 2020 00:59:55 +0100 Subject: [PATCH] spansh.py: added short output format To both station and systems list. Replaces the `--systemlist` switch. --- README.md | 5 ++--- spansh.py | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9ef17f7..bd7950d 100644 --- a/README.md +++ b/README.md @@ -153,15 +153,14 @@ subcommands: ``` usage: spansh.py oldstations [-h] [--system [SYSTEM]] [--count [COUNT]] - [--systemlist] + [--short] optional arguments: -h, --help show this help message and exit --system [SYSTEM] a single system to query. If not present, get the oldest stations overall. --count [COUNT] how many stations to output. Defaults to 50. - --systemlist outputs a list of systems to visit _only_, no station - names (foreasy system names c&p) + --short short output format (system/station names only) ``` ## Need Help / Want to Contribute? ## diff --git a/spansh.py b/spansh.py index b7e91eb..4c6c798 100755 --- a/spansh.py +++ b/spansh.py @@ -9,16 +9,15 @@ from datetime import datetime, timedelta # =========================================================================== -def getOldStations(systemsonly): +def getOldStations(): params = {"json": JSON.dumps({"filters": FILTERS, "sort": SORT, "size": COUNT})} json = requests.post(APIURL, params).json() ret ="" - if systemsonly: - for station in json["results"]: + for station in json["results"]: + if args.short: ret += "{}\n".format(station["system_name"]) - else: - for station in json["results"]: + else: ret += "{}: {} ({})\n".format(station["system_name"], station["name"], station["updated_at"]) @@ -31,9 +30,12 @@ def getOldStationsInSystem(system): ret ="" for station in json["results"]: - ret += "{}, ".format(station["name"]) + if args.short: + ret += "{}\n".format(station["name"]) + else: + ret += "{} ({})\n".format(station["name"], station["updated_at"]) - return ret[:-2] + return ret[:-1] # =========================================================================== @@ -49,9 +51,8 @@ parser_oldstations.add_argument("--system", nargs="?", + "overall.") parser_oldstations.add_argument("--count", nargs="?", type=int, default=50, help="how many stations to output. Defaults to 50.") -parser_oldstations.add_argument("--systemlist", action='store_true', - help="outputs a list of systems to visit _only_, no station names (for" - + "easy system names c&p)") +parser_oldstations.add_argument("--short", action='store_true', + help="short output format (system/station names only)") argcomplete.autocomplete(parser) args = parser.parse_args() @@ -73,7 +74,7 @@ if args.subcommand == "oldstations": if args.system: out = getOldStationsInSystem(args.system) else: - out = getOldStations(args.systemlist) + out = getOldStations() else: parser.print_usage(sys.stderr) sys.exit(1)