Compare commits
25 commits
Author | SHA1 | Date | |
---|---|---|---|
bf31991875 | |||
700df6e98f | |||
fbfaeac64f | |||
a7a44a34b2 | |||
baf0a69396 | |||
bf592168c1 | |||
ebfa86e163 | |||
9e52b9772f | |||
4b8bf96c1c | |||
0176f70c86 | |||
ceccb497dd | |||
e5dcb465fb | |||
20ba6320a5 | |||
e306bd1585 | |||
6b0205e2c1 | |||
718194ccec | |||
92eb2c9008 | |||
0179369fc1 | |||
79bc2d49d4 | |||
c9101ae669 | |||
efa20d3801 | |||
3d4e25866a | |||
4a639f5a0e | |||
d2f01f1456 | |||
cc28fb9314 |
9 changed files with 224 additions and 38 deletions
50
CHANGELOG.md
50
CHANGELOG.md
|
@ -1,3 +1,53 @@
|
||||||
|
# 0.7 (2021-01-28)
|
||||||
|
|
||||||
|
## Changed
|
||||||
|
|
||||||
|
* spansh.py: Fleet carriers are now explicitly excluded from the outdated
|
||||||
|
stations list.
|
||||||
|
|
||||||
|
## Fixed
|
||||||
|
|
||||||
|
* explorationtools.py: Searching for a CMDR with public profile, but hidden
|
||||||
|
activity will no longer error out.
|
||||||
|
* explorationtools.py: Searching for a CMDR with public profile, but hidden
|
||||||
|
flight log will no longer error out.
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
# 0.6 (2020-07-18)
|
||||||
|
|
||||||
|
## Added
|
||||||
|
|
||||||
|
* `spansh.py` old station snearch now takes a `--minage` (in days) argument for
|
||||||
|
what you would consider “outdated” data.
|
||||||
|
|
||||||
|
## Changed
|
||||||
|
|
||||||
|
* `spansh.py` old station search now outputs an age in days for the last update
|
||||||
|
instead of a time stamp.
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
# 0.5 (2020-07-01)
|
||||||
|
|
||||||
|
Changed Changelog format. Should be even clearer now at a glance!
|
||||||
|
|
||||||
|
See [KeepAChangelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
|
## Added
|
||||||
|
|
||||||
|
* `edts.py`: Script for accessing Alot’s hosted EDTS API. Right now the only
|
||||||
|
implemented thing is getting approximate coordinates for a given procedually
|
||||||
|
generated system name.
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
# 0.4.1 (2020-06-18)
|
||||||
|
|
||||||
|
* removed accidentally left over debug print code from `spansh.py`
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
# 0.4 (2020-03-09)
|
# 0.4 (2020-03-09)
|
||||||
|
|
||||||
Kind of a big one. Obviously because in addition to EDSM, I can now do some
|
Kind of a big one. Obviously because in addition to EDSM, I can now do some
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -1,4 +1,4 @@
|
||||||
all: docs
|
all: clean docs release
|
||||||
|
|
||||||
zipfile = elite-scripts.zip
|
zipfile = elite-scripts.zip
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ exe:
|
||||||
pip install --user --upgrade -r requirements.txt
|
pip install --user --upgrade -r requirements.txt
|
||||||
pip install --user --upgrade -r pyEDSM\requirements.txt
|
pip install --user --upgrade -r pyEDSM\requirements.txt
|
||||||
python -OO -m PyInstaller --clean -yF edsm-getnearest.py
|
python -OO -m PyInstaller --clean -yF edsm-getnearest.py
|
||||||
|
python -OO -m PyInstaller --clean -yF edts.py
|
||||||
python -OO -m PyInstaller --clean -yF explorationtools.py
|
python -OO -m PyInstaller --clean -yF explorationtools.py
|
||||||
python -OO -m PyInstaller --clean -yF spansh.py
|
python -OO -m PyInstaller --clean -yF spansh.py
|
||||||
|
|
||||||
|
|
34
README.md
34
README.md
|
@ -44,6 +44,34 @@ optional arguments:
|
||||||
--text explicitly give text output
|
--text explicitly give text output
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### edts.py ###
|
||||||
|
|
||||||
|
```
|
||||||
|
usage: edts.py [-h] {coords} ...
|
||||||
|
|
||||||
|
Script for interfacing with Alot’s hosted EDTS API.
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
|
subcommands:
|
||||||
|
{coords} sub-command help
|
||||||
|
coords Searches for the approximate coordinates of a given procedurally
|
||||||
|
generated system name.
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
usage: edts.py coords [-h] [--maxuncertainty [MAXUNCERTAINTY]] system
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
system the system name to get coordinates for
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--maxuncertainty [MAXUNCERTAINTY]
|
||||||
|
maximum accepted uncertainty, if any
|
||||||
|
```
|
||||||
|
|
||||||
### explorationtools.py ###
|
### explorationtools.py ###
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -171,13 +199,15 @@ optional arguments:
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: spansh.py oldstations [-h] [--system [SYSTEM]] [--count [COUNT]]
|
usage: spansh.py oldstations [-h] [--system [SYSTEM]] [--count [COUNT]]
|
||||||
[--short]
|
[--minage [MINAGE]] [--short]
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
--system [SYSTEM] a single system to query. If not present, get the oldest
|
--system [SYSTEM] a single system to query. If not present, get the oldest
|
||||||
stations overall.
|
stations overall.
|
||||||
--count [COUNT] how many stations to output. Defaults to 50.
|
--count [COUNT] how many stations to output. Defaults to 50.
|
||||||
|
--minage [MINAGE] minimum age of data (in days) to be considered
|
||||||
|
“outdated”. Defaults to 365 (= 1 year).
|
||||||
--short short output format (system/station names only)
|
--short short output format (system/station names only)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -194,4 +224,4 @@ optional arguments:
|
||||||
## Need Help / Want to Contribute? ##
|
## Need Help / Want to Contribute? ##
|
||||||
|
|
||||||
Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new)
|
Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new)
|
||||||
here or [hop into Discord](https://discord.gg/uUKFdW) if that is your thing.
|
here or [hop into Discord](https://discord.gg/XHNX7jN) if that is your thing.
|
||||||
|
|
|
@ -78,9 +78,6 @@ def outputText():
|
||||||
except SystemNotFoundError as e:
|
except SystemNotFoundError as e:
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
except EdsmApiException as e:
|
|
||||||
print(e)
|
|
||||||
sys.exit(1)
|
|
||||||
nearestCmdr = min(distances,key=distances.get)
|
nearestCmdr = min(distances,key=distances.get)
|
||||||
if shortOutput:
|
if shortOutput:
|
||||||
print('nearest commander: {} ({} ly).'.format(nearestCmdr.name,
|
print('nearest commander: {} ({} ly).'.format(nearestCmdr.name,
|
||||||
|
|
77
edts.py
Executable file
77
edts.py
Executable file
|
@ -0,0 +1,77 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# PYTHON_ARGCOMPLETE_OK
|
||||||
|
import argcomplete, argparse
|
||||||
|
import json as JSON
|
||||||
|
import requests
|
||||||
|
import urllib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from pyEDSM.edsm.exception import ServerError, NotFoundError
|
||||||
|
|
||||||
|
# ===========================================================================
|
||||||
|
|
||||||
|
class ProcGenNameError(Exception):
|
||||||
|
def __str__(self):
|
||||||
|
return "Given system is not a valid proc gen name."
|
||||||
|
|
||||||
|
def getCoords(system):
|
||||||
|
url = APIURLS["coords"] + urllib.parse.quote(system)
|
||||||
|
response = requests.get(url)
|
||||||
|
if response.status_code != 200:
|
||||||
|
if response.status_code == 400:
|
||||||
|
raise ProcGenNameError()
|
||||||
|
else:
|
||||||
|
raise ServerError(url, {})
|
||||||
|
|
||||||
|
json = response.json()['result']
|
||||||
|
|
||||||
|
ret = json['position']
|
||||||
|
ret['uncertainty'] = json['uncertainty']
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
# ===========================================================================
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Script for interfacing with "
|
||||||
|
+ "Alot’s hosted EDTS API.")
|
||||||
|
subparsers = parser.add_subparsers(title="subcommands", help="sub-command help",
|
||||||
|
dest="subcommand", required=True)
|
||||||
|
|
||||||
|
parser_coords = subparsers.add_parser("coords",
|
||||||
|
help="Searches for the approximate coordinates of a given procedurally "
|
||||||
|
+ "generated system name.")
|
||||||
|
parser_coords.add_argument("system",
|
||||||
|
help="the system name to get coordinates for")
|
||||||
|
parser_coords.add_argument("--maxuncertainty", nargs="?", type=int,
|
||||||
|
help="maximum accepted uncertainty, if any")
|
||||||
|
|
||||||
|
argcomplete.autocomplete(parser)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# ===========================================================================
|
||||||
|
|
||||||
|
APIURLS = {
|
||||||
|
"coords": "http://edts.thargoid.space/api/v1/system_position/"
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
if args.subcommand == "coords":
|
||||||
|
coords = getCoords(args.system)
|
||||||
|
if args.maxuncertainty:
|
||||||
|
if args.maxuncertainty < coords['uncertainty']:
|
||||||
|
raise NotFoundError()
|
||||||
|
out = "{},{},{}|{}".format(int(coords['x']), int(coords['y']),
|
||||||
|
int(coords['z']), int(coords['uncertainty']))
|
||||||
|
except ServerError as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit(1)
|
||||||
|
except ProcGenNameError as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit(4)
|
||||||
|
except NotFoundError as e:
|
||||||
|
print("Maximum uncertainty exceeded: " + str(int(coords['uncertainty']))
|
||||||
|
+ " > " + str(args.maxuncertainty))
|
||||||
|
sys.exit(3)
|
||||||
|
else:
|
||||||
|
print(out)
|
||||||
|
sys.exit(0)
|
|
@ -22,16 +22,22 @@ def distanceBetween(system1, system2, roundTo=2):
|
||||||
|
|
||||||
def getCommanderPosition(name, apikey):
|
def getCommanderPosition(name, apikey):
|
||||||
coords = Commander(name, apikey).currentPosition
|
coords = Commander(name, apikey).currentPosition
|
||||||
|
ret = "hidden"
|
||||||
|
if coords:
|
||||||
ret = ""
|
ret = ""
|
||||||
for k in coords:
|
for k in coords:
|
||||||
ret += "{}: {}, ".format(k, coords[k])
|
ret += "{}: {}, ".format(k, coords[k])
|
||||||
return ret[:-2]
|
ret = ret[:-2]
|
||||||
|
return ret
|
||||||
|
|
||||||
def getCommanderProfileUrl(name, apikey):
|
def getCommanderProfileUrl(name, apikey):
|
||||||
return Commander(name, apikey).profileUrl
|
return Commander(name, apikey).profileUrl
|
||||||
|
|
||||||
def getCommanderSystem(name, apikey):
|
def getCommanderSystem(name, apikey):
|
||||||
cmdr = Commander(name, apikey)
|
cmdr = Commander(name, apikey)
|
||||||
|
if cmdr.lastActivity is None:
|
||||||
|
return "{}".format(cmdr.currentSystem)
|
||||||
|
else:
|
||||||
return "{} (last seen {})".format(cmdr.currentSystem,
|
return "{} (last seen {})".format(cmdr.currentSystem,
|
||||||
when(cmdr.lastActivity))
|
when(cmdr.lastActivity))
|
||||||
def when(date):
|
def when(date):
|
||||||
|
|
|
@ -34,6 +34,20 @@ EOF
|
||||||
cat >> README.md << EOF
|
cat >> README.md << EOF
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
|
### edts.py ###
|
||||||
|
|
||||||
|
\`\`\`
|
||||||
|
EOF
|
||||||
|
./edts.py -h >> README.md
|
||||||
|
cat >> README.md << EOF
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
\`\`\`
|
||||||
|
EOF
|
||||||
|
./edts.py coords -h >> README.md
|
||||||
|
cat >> README.md << EOF
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
### explorationtools.py ###
|
### explorationtools.py ###
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
@ -101,5 +115,5 @@ cat >> README.md << EOF
|
||||||
## Need Help / Want to Contribute? ##
|
## Need Help / Want to Contribute? ##
|
||||||
|
|
||||||
Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new)
|
Just [file an issue](https://github.com/alterNERDtive/elite-scripts/issues/new)
|
||||||
here or [hop into Discord](https://discord.gg/uUKFdW) if that is your thing.
|
here or [hop into Discord](https://discord.gg/XHNX7jN) if that is your thing.
|
||||||
EOF
|
EOF
|
||||||
|
|
2
pyEDSM
2
pyEDSM
|
@ -1 +1 @@
|
||||||
Subproject commit 36a660f240c7e57cf524fe9640d13e56c7e42e79
|
Subproject commit da044e918fe17cf18d2b2e18d60ce16a168ea70b
|
53
spansh.py
53
spansh.py
|
@ -5,7 +5,8 @@ import json as JSON
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from dateutil import parser as dtparser
|
||||||
|
|
||||||
from pyEDSM.edsm.exception import ServerError, NotFoundError
|
from pyEDSM.edsm.exception import ServerError, NotFoundError
|
||||||
|
|
||||||
|
@ -18,7 +19,6 @@ def querystations(url, params):
|
||||||
json = response.json()
|
json = response.json()
|
||||||
if json["count"] == 0:
|
if json["count"] == 0:
|
||||||
raise NotFoundError()
|
raise NotFoundError()
|
||||||
print(json)
|
|
||||||
return json
|
return json
|
||||||
|
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
|
@ -64,8 +64,8 @@ def getOldStations():
|
||||||
if args.short:
|
if args.short:
|
||||||
ret += "{}\n".format(station["system_name"])
|
ret += "{}\n".format(station["system_name"])
|
||||||
else:
|
else:
|
||||||
ret += "{}: {} ({})\n".format(station["system_name"], station["name"],
|
ret += "{}: {} ({} days ago)\n".format(station["system_name"], station["name"],
|
||||||
station["updated_at"])
|
(datetime.now(timezone.utc) - dtparser.parse(station["updated_at"])).days)
|
||||||
|
|
||||||
return ret[:-1]
|
return ret[:-1]
|
||||||
|
|
||||||
|
@ -80,11 +80,19 @@ def getOldStationsInSystem(system):
|
||||||
json = querystations(APIURLS["stations"], params)
|
json = querystations(APIURLS["stations"], params)
|
||||||
|
|
||||||
ret = ""
|
ret = ""
|
||||||
for station in json["results"]:
|
# exclude carriers
|
||||||
|
stations = list(filter(lambda station: not station["type"] == "Drake-Class Carrier", json["results"]))
|
||||||
|
if len(stations) == 0:
|
||||||
|
raise NotFoundError()
|
||||||
|
for station in stations:
|
||||||
|
# systems including the given name as a word will also trigger;
|
||||||
|
# looking for e.g. “Mari” will also give you stuff in “Mac Mari”!
|
||||||
|
if station["system_name"] == system:
|
||||||
if args.short:
|
if args.short:
|
||||||
ret += "{}\n".format(station["name"])
|
ret += "{}\n".format(station["name"])
|
||||||
else:
|
else:
|
||||||
ret += "{} ({})\n".format(station["name"], station["updated_at"])
|
ret += "{} ({} days ago)\n".format(station["name"],
|
||||||
|
(datetime.now(timezone.utc) - dtparser.parse(station["updated_at"])).days)
|
||||||
|
|
||||||
return ret[:-1]
|
return ret[:-1]
|
||||||
|
|
||||||
|
@ -137,6 +145,9 @@ parser_oldstations.add_argument("--system", nargs="?",
|
||||||
+ "overall.")
|
+ "overall.")
|
||||||
parser_oldstations.add_argument("--count", nargs="?", type=int, default=50,
|
parser_oldstations.add_argument("--count", nargs="?", type=int, default=50,
|
||||||
help="how many stations to output. Defaults to 50.")
|
help="how many stations to output. Defaults to 50.")
|
||||||
|
parser_oldstations.add_argument("--minage", nargs="?", type=int, default=365,
|
||||||
|
help="minimum age of data (in days) to be considered “outdated”. Defaults to "
|
||||||
|
+ "365 (= 1 year).")
|
||||||
parser_oldstations.add_argument("--short", action='store_true',
|
parser_oldstations.add_argument("--short", action='store_true',
|
||||||
help="short output format (system/station names only)")
|
help="short output format (system/station names only)")
|
||||||
|
|
||||||
|
@ -155,26 +166,26 @@ APIURLS = {
|
||||||
"stations": "https://spansh.co.uk/api/stations/search",
|
"stations": "https://spansh.co.uk/api/stations/search",
|
||||||
"systems": "https://spansh.co.uk/api/systems/search",
|
"systems": "https://spansh.co.uk/api/systems/search",
|
||||||
}
|
}
|
||||||
FILTERS = {
|
|
||||||
"updated_at":
|
|
||||||
{
|
|
||||||
"value": [
|
|
||||||
"2017-11-06",
|
|
||||||
(datetime.now() - timedelta(days=365)).strftime("%Y-%m-%d")
|
|
||||||
],
|
|
||||||
"comparison": "<=>"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SORT = {
|
|
||||||
"updated_at": {
|
|
||||||
"direction": "asc"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.subcommand == "nearestsystem":
|
if args.subcommand == "nearestsystem":
|
||||||
out = getNearestSystem(args.coordinate)
|
out = getNearestSystem(args.coordinate)
|
||||||
elif args.subcommand == "oldstations":
|
elif args.subcommand == "oldstations":
|
||||||
|
FILTERS = {
|
||||||
|
"updated_at":
|
||||||
|
{
|
||||||
|
"value": [
|
||||||
|
"2017-11-06",
|
||||||
|
(datetime.now() - timedelta(days=args.minage)).strftime("%Y-%m-%d")
|
||||||
|
],
|
||||||
|
"comparison": "<=>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SORT = {
|
||||||
|
"updated_at": {
|
||||||
|
"direction": "asc"
|
||||||
|
}
|
||||||
|
}
|
||||||
if args.system:
|
if args.system:
|
||||||
out = getOldStationsInSystem(args.system)
|
out = getOldStationsInSystem(args.system)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue