added rounding option to distancebetween
This commit is contained in:
parent
a3b5a82e24
commit
bfad499050
2 changed files with 13 additions and 6 deletions
|
@ -81,13 +81,15 @@ optional arguments:
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: explorationtools.py distancebetween [-h] system system
|
usage: explorationtools.py distancebetween [-h] [--roundto [ROUNDTO]]
|
||||||
|
system system
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
system the systems to measure
|
system the systems to measure
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
--roundto [ROUNDTO] the number of digits to round to (default: 2)
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -12,9 +12,12 @@ from pyEDSM.edsm.models import System, Commander
|
||||||
def getBodyCount(system):
|
def getBodyCount(system):
|
||||||
return System(system).bodyCount
|
return System(system).bodyCount
|
||||||
|
|
||||||
def distanceBetween(system1, system2):
|
def distanceBetween(system1, system2, roundTo=2):
|
||||||
systems = System.getSystems(system1, system2)
|
systems = System.getSystems(system1, system2)
|
||||||
return systems[0].distanceTo(systems[1])
|
distance = systems[0].distanceTo(systems[1], roundTo)
|
||||||
|
if roundTo == 0:
|
||||||
|
distance = int(distance)
|
||||||
|
return distance
|
||||||
|
|
||||||
def getCommanderPosition(name, apikey):
|
def getCommanderPosition(name, apikey):
|
||||||
coords = Commander(name, apikey).currentPosition
|
coords = Commander(name, apikey).currentPosition
|
||||||
|
@ -54,6 +57,8 @@ parser_distance = subparsers.add_parser("distancebetween",
|
||||||
help="Calculates the distance between two systems. Will exit with code 1 "
|
help="Calculates the distance between two systems. Will exit with code 1 "
|
||||||
+ "on server error and code 2 if (one of) the systems could not be found "
|
+ "on server error and code 2 if (one of) the systems could not be found "
|
||||||
+ "on EDSM.")
|
+ "on EDSM.")
|
||||||
|
parser_distance.add_argument("--roundto", nargs="?", type=int, default=2,
|
||||||
|
help="the number of digits to round to (default: 2)")
|
||||||
parser_distance.add_argument("system", nargs=2, help="the systems to measure")
|
parser_distance.add_argument("system", nargs=2, help="the systems to measure")
|
||||||
|
|
||||||
parser_find = subparsers.add_parser("findcommander",
|
parser_find = subparsers.add_parser("findcommander",
|
||||||
|
@ -84,7 +89,7 @@ try:
|
||||||
if args.subCommand == "bodycount":
|
if args.subCommand == "bodycount":
|
||||||
out = getBodyCount(args.system[0])
|
out = getBodyCount(args.system[0])
|
||||||
elif args.subCommand == "distancebetween":
|
elif args.subCommand == "distancebetween":
|
||||||
out = distanceBetween(args.system[0], args.system[1])
|
out = distanceBetween(args.system[0], args.system[1], args.roundto)
|
||||||
elif args.subCommand == "findcommander":
|
elif args.subCommand == "findcommander":
|
||||||
if args.coords:
|
if args.coords:
|
||||||
out = getCommanderPosition(args.name, args.apikey)
|
out = getCommanderPosition(args.name, args.apikey)
|
||||||
|
|
Loading…
Reference in a new issue