spansh.py: added short output format

To both station and systems list. Replaces the `--systemlist` switch.
This commit is contained in:
alterNERDtive 2020-03-08 00:59:55 +01:00
parent adec36ded9
commit 19e8cbfdff
2 changed files with 14 additions and 14 deletions

View file

@ -153,15 +153,14 @@ subcommands:
``` ```
usage: spansh.py oldstations [-h] [--system [SYSTEM]] [--count [COUNT]] usage: spansh.py oldstations [-h] [--system [SYSTEM]] [--count [COUNT]]
[--systemlist] [--short]
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
--system [SYSTEM] a single system to query. If not present, get the oldest --system [SYSTEM] a single system to query. If not present, get the oldest
stations overall. stations overall.
--count [COUNT] how many stations to output. Defaults to 50. --count [COUNT] how many stations to output. Defaults to 50.
--systemlist outputs a list of systems to visit _only_, no station --short short output format (system/station names only)
names (foreasy system names c&p)
``` ```
## Need Help / Want to Contribute? ## ## Need Help / Want to Contribute? ##

View file

@ -9,16 +9,15 @@ from datetime import datetime, timedelta
# =========================================================================== # ===========================================================================
def getOldStations(systemsonly): def getOldStations():
params = {"json": JSON.dumps({"filters": FILTERS, "sort": SORT, "size": COUNT})} params = {"json": JSON.dumps({"filters": FILTERS, "sort": SORT, "size": COUNT})}
json = requests.post(APIURL, params).json() json = requests.post(APIURL, params).json()
ret ="" ret =""
if systemsonly: for station in json["results"]:
for station in json["results"]: if args.short:
ret += "{}\n".format(station["system_name"]) ret += "{}\n".format(station["system_name"])
else: else:
for station in json["results"]:
ret += "{}: {} ({})\n".format(station["system_name"], station["name"], ret += "{}: {} ({})\n".format(station["system_name"], station["name"],
station["updated_at"]) station["updated_at"])
@ -31,9 +30,12 @@ def getOldStationsInSystem(system):
ret ="" ret =""
for station in json["results"]: 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.") + "overall.")
parser_oldstations.add_argument("--count", nargs="?", type=int, default=50, parser_oldstations.add_argument("--count", nargs="?", type=int, default=50,
help="how many stations to output. Defaults to 50.") help="how many stations to output. Defaults to 50.")
parser_oldstations.add_argument("--systemlist", action='store_true', parser_oldstations.add_argument("--short", action='store_true',
help="outputs a list of systems to visit _only_, no station names (for" help="short output format (system/station names only)")
+ "easy system names c&p)")
argcomplete.autocomplete(parser) argcomplete.autocomplete(parser)
args = parser.parse_args() args = parser.parse_args()
@ -73,7 +74,7 @@ if args.subcommand == "oldstations":
if args.system: if args.system:
out = getOldStationsInSystem(args.system) out = getOldStationsInSystem(args.system)
else: else:
out = getOldStations(args.systemlist) out = getOldStations()
else: else:
parser.print_usage(sys.stderr) parser.print_usage(sys.stderr)
sys.exit(1) sys.exit(1)