From 6ff10430eb698689789375f1ebe9be1a62ca30f7 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Wed, 8 Jan 2020 08:49:53 +0100 Subject: [PATCH] added `--coords` option to `findcommander` --- README.md | 5 ++++- explorationtools.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 00e3f95..fc2b661 100644 --- a/README.md +++ b/README.md @@ -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: name the commander in question @@ -85,6 +86,8 @@ positional arguments: optional arguments: -h, --help show this help message and exit --system output the commander’s last known system (default) + --coords output the commander’s last known position in {x,y,z} + coordinates --url output the commander’s profile URL ``` diff --git a/explorationtools.py b/explorationtools.py index a84ea59..32ea660 100755 --- a/explorationtools.py +++ b/explorationtools.py @@ -19,6 +19,13 @@ def distanceBetween(system1, system2): + (coords1['y']-coords2['y'])**2 + (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): 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.add_argument('--system', action='store_true', help='output the commander’s last known system (default)') +group.add_argument('--coords', action='store_true', + help='output the commander’s last known position in {x,y,z} coordinates') group.add_argument('--url', action='store_true', help='output the commander’s profile URL') parser_find.add_argument("name", help="the commander in question") @@ -66,7 +75,9 @@ try: elif args.subCommand == "distancebetween": out = distanceBetween(args.system[0], args.system[1]) 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) else: out = getCommanderSystem(args.name, args.apikey)