added option to get profileURL to findcommander

This commit is contained in:
alterNERDtive 2020-01-07 17:27:31 +01:00
parent 1f113611d4
commit dfeb6993b0
2 changed files with 15 additions and 2 deletions

View file

@ -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 commanders last known system (default)
--url output the commanders profile URL
```

View file

@ -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 CMDRs 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 commanders last known system (default)')
group.add_argument('--url', action='store_true',
help='output the commanders profile URL')
parser_find.add_argument("name", help="the commander in question")
parser_find.add_argument("apikey", default="", nargs="?",
help="the commanders 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)