added explorationtools.py

For now only has a single subcommend, `bodycount`. It returns the number
of bodies in a system.
This commit is contained in:
alterNERDtive 2019-10-04 00:45:33 +02:00
parent 5d9a3dcfc9
commit 57ffbc8559
3 changed files with 69 additions and 1 deletions

View file

@ -19,3 +19,30 @@ optional arguments:
--gui explicitly run the GUI
--text explicitly give text output
```
## explorationtools.py ##
```
usage: explorationtools.py [-h] {bodycount} ...
A collection of tools useful for exploration.
optional arguments:
-h, --help show this help message and exit
subcommands:
{bodycount} sub-command help
bodycount 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.
```
```
usage: explorationtools.py bodycount [-h] system
positional arguments:
system the system in question
optional arguments:
-h, --help show this help message and exit
```

41
explorationtools.py Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env python3
import argparse
import math
import sys
from pyEDSM.edsm.exception import ServerError, NotFoundError
from pyEDSM.edsm.models import System, Commander
# ===========================================================================
def getBodyCount(system):
try:
bodyCount = System(system).bodyCount
except ServerError as e:
print(e)
sys.exit(1)
except NotFoundError as e:
print(e)
sys.exit(2)
else:
print(bodyCount)
sys.exit(0)
# ===========================================================================
parser = argparse.ArgumentParser(description="A collection of tools useful for "
+ "exploration.")
subparsers = parser.add_subparsers(title="subcommands", help="sub-command help",
dest="subCommand")
parser_bodycount = subparsers.add_parser("bodycount",
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.")
parser_bodycount.add_argument("system", nargs=1, help="the system in question")
args = parser.parse_args()
# ===========================================================================
if args.subCommand == "bodycount":
getBodyCount(args.system[0])

2
pyEDSM

@ -1 +1 @@
Subproject commit 573c6c322ff27e304fc2dd803f362156f8d45dbb
Subproject commit f0a54a7fe4cbc8c6fdab20fdceb1107e5c50f1bd