diff --git a/README.md b/README.md index be7b482..64fc9a7 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ optional arguments: ``` usage: explorationtools.py [-h] - {bodycount,distancebetween,findcommander,systemlist} + {bodycount,distancebetween,findcommander,findsystem,systemlist} ... A collection of tools useful for exploration. @@ -55,7 +55,7 @@ optional arguments: -h, --help show this help message and exit subcommands: - {bodycount,distancebetween,findcommander,systemlist} + {bodycount,distancebetween,findcommander,findsystem,systemlist} 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 @@ -66,6 +66,9 @@ subcommands: findcommander Attempts to find a CMDR’s last known position. Will exit with code 1 on server error and code 2 if the CMDR could not be found on EDSM. + findsystem Attempts to find a partially matching system that + should then hopefully be in the vicinity of the given + system systemlist Pulls all system names starting with the given string from EDSM ``` @@ -108,6 +111,16 @@ optional arguments: --url output the commander’s profile URL ``` +``` +usage: explorationtools.py findsystem [-h] system + +positional arguments: + system the system in question + +optional arguments: + -h, --help show this help message and exit +``` + ``` usage: explorationtools.py systemlist [-h] partialsystem diff --git a/explorationtools.py b/explorationtools.py index f412d17..780cc32 100755 --- a/explorationtools.py +++ b/explorationtools.py @@ -33,14 +33,31 @@ def getCommanderSystem(name, apikey): return Commander(name, apikey).currentSystem def getSystemList(name): - ret = "" - systems = System.getSystems(name) + ret = "" for system in systems: ret += "{}\n".format(system.name) - return ret[:-1] +def getSystemNear(name): + # Probably want to abort at _some_ point. I’m defining two full words left as + # the condition for that now. + if name.count(' ') < 2: + ret = "Aborting search at {}, require more than 2 words to limit the " + ret += "result set." + return ret.format(name) + + try: + systems = System.getSystems(name) + except NotFoundError: + return getSystemNear(name[:-1]) + else: + ret = "" + for system in systems: + ret += "{} ({}, {}, {})\n".format(system.name, + system.coords['x'], system.coords['y'], system.coords['z']) + return ret[:-1] + # =========================================================================== parser = argparse.ArgumentParser(description="A collection of tools useful for " @@ -61,20 +78,25 @@ 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_find = subparsers.add_parser("findcommander", +parser_findCmdr = subparsers.add_parser("findcommander", help="Attempts to find a CMDR’s last known position. Will exit with code 1 " + "on server error and code 2 if the CMDR could not be found on EDSM.") -group = parser_find.add_mutually_exclusive_group(required=False) +group = parser_findCmdr.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") -parser_find.add_argument("apikey", default="", nargs="?", +parser_findCmdr.add_argument("name", help="the commander in question") +parser_findCmdr.add_argument("apikey", default="", nargs="?", help="the commander’s EDSM API key. Can be empty for public profiles.") +parser_findSystem = subparsers.add_parser("findsystem", + help="Attempts to find a partially matching system that should then " + + "hopefully be in the vicinity of the given system") +parser_findSystem.add_argument("system", help="the system in question") + parser_bodycount = subparsers.add_parser("systemlist", help="Pulls all system names starting with the given string from EDSM") parser_bodycount.add_argument("partialsystem", nargs=1, @@ -97,8 +119,13 @@ try: out = getCommanderProfileUrl(args.name, args.apikey) else: out = getCommanderSystem(args.name, args.apikey) + elif args.subCommand == "findsystem": + out = getSystemNear(args.system) elif args.subCommand == "systemlist": out = getSystemList(args.partialsystem) + else: + parser.print_usage() + sys.exit(1) except ServerError as e: print(e) sys.exit(1) diff --git a/generate_docs.sh b/generate_docs.sh index 76e148c..a519a2e 100644 --- a/generate_docs.sh +++ b/generate_docs.sh @@ -58,6 +58,12 @@ EOF cat >> README.md << EOF \`\`\` +\`\`\` +EOF +./explorationtools.py findsystem -h >> README.md +cat >> README.md << EOF +\`\`\` + \`\`\` EOF ./explorationtools.py systemlist -h >> README.md