From dfeb6993b05ade297d118b6922434555fe423b91 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Tue, 7 Jan 2020 17:27:31 +0100 Subject: [PATCH] added option to get profileURL to `findcommander` --- README.md | 4 +++- explorationtools.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 654df79..82b1d9c 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ optional arguments: ``` ``` -usage: explorationtools.py findcommander [-h] name [apikey] +usage: explorationtools.py findcommander [-h] [--system | --url] name [apikey] positional arguments: name the commander in question @@ -73,4 +73,6 @@ positional arguments: optional arguments: -h, --help show this help message and exit + --system output the commander’s last known system (default) + --url output the commander’s profile URL ``` diff --git a/explorationtools.py b/explorationtools.py index 2cafd00..6aa3456 100755 --- a/explorationtools.py +++ b/explorationtools.py @@ -19,6 +19,9 @@ def distanceBetween(system1, system2): def findCommander(name, apikey): return Commander(name, apikey).currentSystem +def getProfileUrl(name, apikey): + return Commander(name, apikey).profileUrl + def getBodyCount(system): return System(system).bodyCount @@ -43,6 +46,11 @@ parser_distance.add_argument("system", nargs=2, help="the systems to measure") parser_find = subparsers.add_parser("findcommander", help="Attempts to find a CMDR’s last known position. Will exit with code 1 " + "on server error and code 2 if the CMDR could not be found on EDSM.") +group = parser_find.add_mutually_exclusive_group(required=False) +group.add_argument('--system', action='store_true', + help='output the commander’s last known system (default)') +group.add_argument('--url', action='store_true', + help='output the commander’s profile URL') parser_find.add_argument("name", help="the commander in question") parser_find.add_argument("apikey", default="", nargs="?", help="the commander’s EDSM API key. Can be empty for public profiles.") @@ -58,7 +66,10 @@ try: elif args.subCommand == "distancebetween": out = distanceBetween(args.system[0], args.system[1]) elif args.subCommand == "findcommander": - out = findCommander(args.name, args.apikey) + if args.url: + out = getProfileUrl(args.name, args.apikey) + else: + out = findCommander(args.name, args.apikey) except ServerError as e: print(e) sys.exit(1)