From 57ffbc85594623aa6a864332f926ea7c3f5077c9 Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Fri, 4 Oct 2019 00:45:33 +0200 Subject: [PATCH] added `explorationtools.py` For now only has a single subcommend, `bodycount`. It returns the number of bodies in a system. --- README.md | 27 +++++++++++++++++++++++++++ explorationtools.py | 41 +++++++++++++++++++++++++++++++++++++++++ pyEDSM | 2 +- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 explorationtools.py diff --git a/README.md b/README.md index eec2ee9..ddeaee5 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/explorationtools.py b/explorationtools.py new file mode 100755 index 0000000..6cedb93 --- /dev/null +++ b/explorationtools.py @@ -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]) diff --git a/pyEDSM b/pyEDSM index 573c6c3..f0a54a7 160000 --- a/pyEDSM +++ b/pyEDSM @@ -1 +1 @@ -Subproject commit 573c6c322ff27e304fc2dd803f362156f8d45dbb +Subproject commit f0a54a7fe4cbc8c6fdab20fdceb1107e5c50f1bd