added distancebetween
subcommand
Returns the distance between two systems.
This commit is contained in:
parent
57ffbc8559
commit
b697a30f75
2 changed files with 46 additions and 8 deletions
28
README.md
28
README.md
|
@ -23,25 +23,39 @@ optional arguments:
|
||||||
## explorationtools.py ##
|
## explorationtools.py ##
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: explorationtools.py [-h] {bodycount} ...
|
usage: explorationtools.py [-h] {bodycount,distancebetween} ...
|
||||||
|
|
||||||
A collection of tools useful for exploration.
|
A collection of tools useful for exploration.
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
subcommands:
|
subcommands:
|
||||||
{bodycount} sub-command help
|
{bodycount,distancebetween}
|
||||||
bodycount Returns the number of bodies in a system. Will exit with code 1
|
sub-command help
|
||||||
on server error and code 2 if the system could not be found in
|
bodycount Returns the number of bodies in a system. Will exit
|
||||||
EDSM.
|
with code 1 on server error and code 2 if the system
|
||||||
|
could not be found in EDSM.
|
||||||
|
distancebetween Calculates the distance between two systems. Will exti
|
||||||
|
with code 1 on server error and code 2 if (one of) the
|
||||||
|
systems could not be found on EDSM.
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: explorationtools.py bodycount [-h] system
|
usage: explorationtools.py bodycount [-h] system
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
system the system in question
|
system
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
usage: explorationtools.py distancebetween [-h] system system
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
system
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
|
@ -21,6 +21,22 @@ def getBodyCount(system):
|
||||||
print(bodyCount)
|
print(bodyCount)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
def distanceBetween(system1, system2):
|
||||||
|
try:
|
||||||
|
coords1 = System(system1).coords
|
||||||
|
coords2 = System(system2).coords
|
||||||
|
except ServerError as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit(1)
|
||||||
|
except NotFoundError as e:
|
||||||
|
print(e)
|
||||||
|
syst.exit(2)
|
||||||
|
else:
|
||||||
|
print(int(round(math.sqrt( (coords1['x']-coords2['x'])**2
|
||||||
|
+ (coords1['y']-coords2['y'])**2
|
||||||
|
+ (coords1['z']-coords2['z'])**2 ),0)))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="A collection of tools useful for "
|
parser = argparse.ArgumentParser(description="A collection of tools useful for "
|
||||||
|
@ -31,7 +47,13 @@ subparsers = parser.add_subparsers(title="subcommands", help="sub-command help",
|
||||||
parser_bodycount = subparsers.add_parser("bodycount",
|
parser_bodycount = subparsers.add_parser("bodycount",
|
||||||
help="Returns the number of bodies in a system. Will exit with code 1 on "
|
help="Returns the number of bodies in a system. Will exit with code 1 on "
|
||||||
+ "server error and code 2 if the system could not be found in EDSM.")
|
+ "server error and code 2 if the system could not be found in EDSM.")
|
||||||
parser_bodycount.add_argument("system", nargs=1, help="the system in question")
|
parser_bodycount.add_argument("system", nargs=1)
|
||||||
|
|
||||||
|
parser_distance = subparsers.add_parser("distancebetween",
|
||||||
|
help="Calculates the distance between two systems. Will exti with code 1 "
|
||||||
|
+ "on server error and code 2 if (one of) the systems could not be found "
|
||||||
|
+ "on EDSM.")
|
||||||
|
parser_distance.add_argument("system", nargs=2)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -39,3 +61,5 @@ args = parser.parse_args()
|
||||||
|
|
||||||
if args.subCommand == "bodycount":
|
if args.subCommand == "bodycount":
|
||||||
getBodyCount(args.system[0])
|
getBodyCount(args.system[0])
|
||||||
|
elif args.subCommand == "distancebetween":
|
||||||
|
distanceBetween(args.system[0], args.system[1])
|
||||||
|
|
Loading…
Reference in a new issue