diff --git a/README.md b/README.md index cf10c30..c68716e 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ optional arguments: ### spansh.py ### ``` -usage: spansh.py [-h] {nearestsystem,oldstations} ... +usage: spansh.py [-h] {nearestsystem,oldstations,systemexists} ... Script for interfacing with Spansh’s API. @@ -146,12 +146,14 @@ optional arguments: -h, --help show this help message and exit subcommands: - {nearestsystem,oldstations} + {nearestsystem,oldstations,systemexists} sub-command help nearestsystem Searches for the nearest system in the database to given coordinates. oldstations Searches for stations with old data (>1 year without an update. + systemexists Checks if a given system exists in the search + database. ``` ``` @@ -179,6 +181,16 @@ optional arguments: --short short output format (system/station names only) ``` +``` +usage: spansh.py systemexists [-h] system + +positional arguments: + system the system to search for + +optional arguments: + -h, --help show this help message and exit +``` + ## Need Help / Want to Contribute? ## Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new) diff --git a/generate_docs.sh b/generate_docs.sh index cb9a73f..c790f2b 100644 --- a/generate_docs.sh +++ b/generate_docs.sh @@ -92,6 +92,12 @@ EOF cat >> README.md << EOF \`\`\` +\`\`\` +EOF +./spansh.py systemexists -h >> README.md +cat >> README.md << EOF +\`\`\` + ## Need Help / Want to Contribute? ## Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new) diff --git a/spansh.py b/spansh.py index 59a5850..4d697d8 100755 --- a/spansh.py +++ b/spansh.py @@ -88,6 +88,31 @@ def getOldStationsInSystem(system): return ret[:-1] +def systemExists(system): + params = { + "json": JSON.dumps({ + "filters": { + "name": { + "value": system + } + } + }) + } + response = requests.post(APIURLS["systems"], params) + if response.status_code != 200: + raise ServerError(url, params) + + json = response.json() + if json["count"] == 0: + raise NotFoundError() + + ret = "" + for system in json["results"]: + ret += "{} ({}, {}, {})\n".format(system["name"], system["x"], system["y"], + system["z"]) + + return ret[:-1] + # =========================================================================== parser = argparse.ArgumentParser(description="Script for interfacing with " @@ -115,14 +140,20 @@ parser_oldstations.add_argument("--count", nargs="?", type=int, default=50, parser_oldstations.add_argument("--short", action='store_true', help="short output format (system/station names only)") +parser_systemexists = subparsers.add_parser("systemexists", + help="Checks if a given system exists in the search database.") +parser_systemexists.add_argument("system", nargs=1, + help="the system to search for") + argcomplete.autocomplete(parser) args = parser.parse_args() # =========================================================================== APIURLS = { + "nearest": "https://spansh.co.uk/api/nearest", "stations": "https://spansh.co.uk/api/stations/search", - "nearest": "https://spansh.co.uk/api/nearest" + "systems": "https://spansh.co.uk/api/systems/search", } FILTERS = { "updated_at": @@ -148,6 +179,8 @@ try: out = getOldStationsInSystem(args.system) else: out = getOldStations() + elif args.subcommand == "systemexists": + out = systemExists(args.system) except ServerError as e: print(e) sys.exit(1)