added spansh.py for Spansh API related shenanigans

This commit is contained in:
alterNERDtive 2020-03-04 18:07:56 +01:00
parent 0f30584bf3
commit 95f5de2377
4 changed files with 115 additions and 0 deletions

View file

@ -14,6 +14,7 @@ exe:
pip install --user --upgrade -r pyEDSM\requirements.txt
python -OO -m PyInstaller --clean -yF edsm-getnearest.py
python -OO -m PyInstaller --clean -yF explorationtools.py
python -OO -m PyInstaller --clean -yF spansh.py
# probably wont work unless youre me :)
release: clean

View file

@ -135,6 +135,35 @@ optional arguments:
-h, --help show this help message and exit
```
### spansh.py ###
```
usage: spansh.py [-h] {oldstations} ...
Script for interfacing with Spanshs API.
optional arguments:
-h, --help show this help message and exit
subcommands:
{oldstations} sub-command help
oldstations Searches for stations with old data (>1year without an
update.
```
```
usage: spansh.py oldstations [-h] [--system [SYSTEM]] [--count [COUNT]]
[--systemlist]
optional arguments:
-h, --help show this help message and exit
--system [SYSTEM] a single system to query. If not present, get the oldest
stations overall.
--count [COUNT] how many stations to output. Defaults to 50.
--systemlist outputs a list of systems to visit _only_, no station
names (for)easy system names c&p
```
## Need Help / Want to Contribute? ##
Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new)

View file

@ -72,6 +72,20 @@ EOF
cat >> README.md << EOF
\`\`\`
### spansh.py ###
\`\`\`
EOF
./spansh.py -h >> README.md
cat >> README.md << EOF
\`\`\`
\`\`\`
EOF
./spansh.py oldstations -h >> README.md
cat >> README.md << EOF
\`\`\`
## Need Help / Want to Contribute? ##
Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new)

71
spansh.py Executable file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
import argcomplete, argparse
import requests
import sys
# ===========================================================================
def getOldStations(count, systemsonly):
url = "http://backend3.spansh.co.uk:3000/api/stations/search"
params = {"json": '{"filters":{"updated_at":{"value":["2017-11-06","2019-03-01"],"comparison":"<=>"}},"sort":[{"updated_at":{"direction":"asc"}}],"size":' + str(count) + '}'}
json = requests.post(url, params).json()
ret =""
if systemsonly:
for station in json["results"]:
ret += "{}\n".format(station["system_name"])
else:
for station in json["results"]:
ret += "{}: {} ({})\n".format(station["system_name"], station["name"],
station["updated_at"])
return ret[:-1]
def getOldStationsInSystem(system):
url = "http://backend3.spansh.co.uk:3000/api/stations/search"
params = {"json": '{"filters": {"system_name": {"value": "' + system + '"},"updated_at":{"value":["2017-11-06","2019-03-01"],"comparison":"<=>"}},"sort":[{"updated_at":{"direction":"asc"}}]}'}
json = requests.post(url, params).json()
ret =""
for station in json["results"]:
ret += "{}, ".format(station["name"])
return ret[:-2]
# ===========================================================================
parser = argparse.ArgumentParser(description="Script for interfacing with "
+ "Spanshs API.")
subparsers = parser.add_subparsers(title="subcommands", help="sub-command help",
dest="subcommand", required=True)
parser_oldstations = subparsers.add_parser("oldstations",
help="Searches for stations with old data (>1year without an update.")
parser_oldstations.add_argument("--system", nargs="?",
help="a single system to query. If not present, get the oldest stations "
+ "overall.")
parser_oldstations.add_argument("--count", nargs="?", type=int, default=50,
help="how many stations to output. Defaults to 50.")
parser_oldstations.add_argument("--systemlist", action='store_true',
help="outputs a list of systems to visit _only_, no station names (for)"
+ "easy system names c&p")
argcomplete.autocomplete(parser)
args = parser.parse_args()
# ===========================================================================
out =""
if args.subcommand == "oldstations":
if args.system:
out = getOldStationsInSystem(args.system)
else:
out = getOldStations(args.count, args.systemlist)
print(out)
sys.exit(0)