parent
9788b4589b
commit
84e21b8041
3 changed files with 13 additions and 19 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "pyEDSM"]
|
||||||
|
path = pyEDSM
|
||||||
|
url = https://github.com/alterNERDtive/pyEDSM
|
|
@ -5,21 +5,11 @@ import requests
|
||||||
import sys
|
import sys
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
|
from pyEDSM.edsm.exception import ServerError, NotFoundError
|
||||||
|
from pyEDSM.edsm.models import System, Commander
|
||||||
|
|
||||||
# =================================================================================
|
# =================================================================================
|
||||||
|
|
||||||
class EdsmApiException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def getSystemCoords (system):
|
|
||||||
resp = requests.get('https://www.edsm.net/api-v1/system?systemName={}&showCoordinates=1'.format(system))
|
|
||||||
if resp.status_code != 200:
|
|
||||||
raise EdsmApiException('GET /system/ {}'.format(resp.status_code))
|
|
||||||
try:
|
|
||||||
ret = resp.json()['coords']
|
|
||||||
except TypeError:
|
|
||||||
raise EdsmApiException('System coordinates for {} not found!'.format(system))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def getCmdrCoords (cmdr):
|
def getCmdrCoords (cmdr):
|
||||||
resp = requests.get('https://www.edsm.net/api-logs-v1/get-position?commanderName={}&showCoordinates=1'.format(cmdr))
|
resp = requests.get('https://www.edsm.net/api-logs-v1/get-position?commanderName={}&showCoordinates=1'.format(cmdr))
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
|
@ -31,12 +21,12 @@ def getCmdrCoords (cmdr):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def distance (coords1, coords2):
|
def distance (coords1, coords2):
|
||||||
return math.sqrt( (coords1['x']-coords2['x'])**2
|
return math.sqrt( (coords1['x']-coords2['x'])**2
|
||||||
+ (coords1['y']-coords2['y'])**2
|
+ (coords1['y']-coords2['y'])**2
|
||||||
+ (coords1['z']-coords2['z'])**2 )
|
+ (coords1['z']-coords2['z'])**2 )
|
||||||
|
|
||||||
def getDistances (system, cmdrs):
|
def getDistances (system, cmdrs):
|
||||||
systemcoords = getSystemCoords(system)
|
systemcoords = System(system).coords
|
||||||
distances = {}
|
distances = {}
|
||||||
for cmdr in cmdrs:
|
for cmdr in cmdrs:
|
||||||
cmdrcoords = getCmdrCoords(cmdr)
|
cmdrcoords = getCmdrCoords(cmdr)
|
||||||
|
@ -64,7 +54,7 @@ def outputGui():
|
||||||
lbl.grid(row=row, column=0)
|
lbl.grid(row=row, column=0)
|
||||||
lbl = tk.Label(frame, text='{} ly'.format(distances[cmdr]))
|
lbl = tk.Label(frame, text='{} ly'.format(distances[cmdr]))
|
||||||
lbl.grid(row=row, column=1)
|
lbl.grid(row=row, column=1)
|
||||||
except EdsmApiException as e:
|
except (ServerError, NotFoundError) as e:
|
||||||
lbl = tk.Label(frame, text=e)
|
lbl = tk.Label(frame, text=e)
|
||||||
lbl.grid(row=0, columnspan=2)
|
lbl.grid(row=0, columnspan=2)
|
||||||
window = tk.Tk()
|
window = tk.Tk()
|
||||||
|
@ -89,15 +79,15 @@ def outputGui():
|
||||||
def outputText():
|
def outputText():
|
||||||
try:
|
try:
|
||||||
distances = getDistances(system, cmdrs)
|
distances = getDistances(system, cmdrs)
|
||||||
except EdsmApiException as e:
|
except (ServerError, NotFoundErorr) as e:
|
||||||
print(e)
|
print(e)
|
||||||
exit(1)
|
exit(1)
|
||||||
nearestCmdr = min(distances,key=distances.get)
|
nearestCmdr = min(distances,key=distances.get)
|
||||||
if shortOutput:
|
if shortOutput:
|
||||||
print('nearest commander: {} ({} ly).'.format(nearestCmdr,
|
print('nearest commander: {} ({} ly).'.format(nearestCmdr,
|
||||||
distances[nearestCmdr]))
|
distances[nearestCmdr]))
|
||||||
else:
|
else:
|
||||||
print('nearest CMDR: {} ({} ly from {}).'.format(nearestCmdr,
|
print('nearest CMDR: {} ({} ly from {}).'.format(nearestCmdr,
|
||||||
distances[nearestCmdr], system))
|
distances[nearestCmdr], system))
|
||||||
print()
|
print()
|
||||||
for cmdr in distances:
|
for cmdr in distances:
|
||||||
|
|
1
pyEDSM
Submodule
1
pyEDSM
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 13d766a2b9305c009b985be6d79fac7fdb1bf960
|
Loading…
Reference in a new issue