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 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):
|
||||
resp = requests.get('https://www.edsm.net/api-logs-v1/get-position?commanderName={}&showCoordinates=1'.format(cmdr))
|
||||
if resp.status_code != 200:
|
||||
|
@ -36,7 +26,7 @@ def distance (coords1, coords2):
|
|||
+ (coords1['z']-coords2['z'])**2 )
|
||||
|
||||
def getDistances (system, cmdrs):
|
||||
systemcoords = getSystemCoords(system)
|
||||
systemcoords = System(system).coords
|
||||
distances = {}
|
||||
for cmdr in cmdrs:
|
||||
cmdrcoords = getCmdrCoords(cmdr)
|
||||
|
@ -64,7 +54,7 @@ def outputGui():
|
|||
lbl.grid(row=row, column=0)
|
||||
lbl = tk.Label(frame, text='{} ly'.format(distances[cmdr]))
|
||||
lbl.grid(row=row, column=1)
|
||||
except EdsmApiException as e:
|
||||
except (ServerError, NotFoundError) as e:
|
||||
lbl = tk.Label(frame, text=e)
|
||||
lbl.grid(row=0, columnspan=2)
|
||||
window = tk.Tk()
|
||||
|
@ -89,7 +79,7 @@ def outputGui():
|
|||
def outputText():
|
||||
try:
|
||||
distances = getDistances(system, cmdrs)
|
||||
except EdsmApiException as e:
|
||||
except (ServerError, NotFoundErorr) as e:
|
||||
print(e)
|
||||
exit(1)
|
||||
nearestCmdr = min(distances,key=distances.get)
|
||||
|
|
1
pyEDSM
Submodule
1
pyEDSM
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 13d766a2b9305c009b985be6d79fac7fdb1bf960
|
Loading…
Reference in a new issue