added --coords option to findcommander

This commit is contained in:
alterNERDtive 2020-01-08 08:49:53 +01:00
parent 3def9ad3c3
commit 6ff10430eb
2 changed files with 16 additions and 2 deletions

View file

@ -76,7 +76,8 @@ optional arguments:
``` ```
``` ```
usage: explorationtools.py findcommander [-h] [--system | --url] name [apikey] usage: explorationtools.py findcommander [-h] [--system | --coords | --url]
name [apikey]
positional arguments: positional arguments:
name the commander in question name the commander in question
@ -85,6 +86,8 @@ positional arguments:
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
--system output the commanders last known system (default) --system output the commanders last known system (default)
--coords output the commanders last known position in {x,y,z}
coordinates
--url output the commanders profile URL --url output the commanders profile URL
``` ```

View file

@ -19,6 +19,13 @@ def distanceBetween(system1, system2):
+ (coords1['y']-coords2['y'])**2 + (coords1['y']-coords2['y'])**2
+ (coords1['z']-coords2['z'])**2 ),0)) + (coords1['z']-coords2['z'])**2 ),0))
def getCommanderPosition(name, apikey):
coords = Commander(name, apikey).currentPosition
ret = ""
for k in coords:
ret += "{}: {}, ".format(k, coords[k])
return ret[:-2]
def getCommanderProfileUrl(name, apikey): def getCommanderProfileUrl(name, apikey):
return Commander(name, apikey).profileUrl return Commander(name, apikey).profileUrl
@ -49,6 +56,8 @@ parser_find = subparsers.add_parser("findcommander",
group = parser_find.add_mutually_exclusive_group(required=False) group = parser_find.add_mutually_exclusive_group(required=False)
group.add_argument('--system', action='store_true', group.add_argument('--system', action='store_true',
help='output the commanders last known system (default)') help='output the commanders last known system (default)')
group.add_argument('--coords', action='store_true',
help='output the commanders last known position in {x,y,z} coordinates')
group.add_argument('--url', action='store_true', group.add_argument('--url', action='store_true',
help='output the commanders profile URL') help='output the commanders profile URL')
parser_find.add_argument("name", help="the commander in question") parser_find.add_argument("name", help="the commander in question")
@ -66,7 +75,9 @@ try:
elif args.subCommand == "distancebetween": elif args.subCommand == "distancebetween":
out = distanceBetween(args.system[0], args.system[1]) out = distanceBetween(args.system[0], args.system[1])
elif args.subCommand == "findcommander": elif args.subCommand == "findcommander":
if args.url: if args.coords:
out = getCommanderPosition(args.name, args.apikey)
elif args.url:
out = getCommanderProfileUrl(args.name, args.apikey) out = getCommanderProfileUrl(args.name, args.apikey)
else: else:
out = getCommanderSystem(args.name, args.apikey) out = getCommanderSystem(args.name, args.apikey)