Skip to content

Instantly share code, notes, and snippets.

@andybish
Created November 1, 2017 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andybish/19164002eedb67a06d92821e1d2fdd7b to your computer and use it in GitHub Desktop.
Save andybish/19164002eedb67a06d92821e1d2fdd7b to your computer and use it in GitHub Desktop.
import requests
edsm_url = 'https://www.edsm.net/api-v1/sphere-systems'
system_url = 'https://system.api.fuelrats.com/populated_systems'
station_url = 'https://system.api.fuelrats.com/stations'
max_dist = 10000
def getNearestScoopable(system):
params = {'systemName':system, 'radius':50, 'showPermit':1, 'showPrimaryStar':1}
req = requests.get(edsm_url, params=params)
systems = req.json()
scoopable = [x for x in systems if x['primaryStar']['isScoopable']
and x['requirePermit'] == False]
scoopable.sort(key=lambda k: int(k['distance']))
print('Nearest scoopable star: ' + scoopable[0]['name'] + ' is ' + str(scoopable[0]['distance'])
+ 'LY away, type is ' + scoopable[0]['primaryStar']['type'])
def getNearestRefuel(system, exclude = False, pad = None, horizons = True, distance = None):
if distance: maxdistance = max(distance,max_dist)
else: maxdistance = max_dist
edsm_params = {'systemName':system, 'radius':50, 'showPermit':1,
'showInformation':1, 'showId':1}
edsm_req = requests.get(edsm_url, params=edsm_params)
edsm_systems = edsm_req.json()
edsm_popsys = [x for x in edsm_systems if x['information'] != []
and x['requirePermit'] == False]
edsm_popsys.sort(key=lambda k: float(k['distance']))
if exclude: edsm_popsys = edsm_popsys[1:]
for i, sys1 in enumerate(edsm_popsys):
print('\r{:5.2f}LY'.format(sys1['distance']), end = '', flush=True)
system_params = {'filter[edsm_id:eq]':sys1['id']}
system_request = requests.get(system_url, params=system_params)
nearsys = system_request.json()
if len(nearsys['data'])==0: continue
station_params = {'filter[system_id:eq]':nearsys['data'][0]['id'],
'filter[has_refuel:eq]':True}
if pad: station_params['filter[max_landing_pad_size:eq]'] = pad
if not horizons: station_params['filter[is_planetary:eq]'] = False
if distance: station_params['filter[distance_to_star:lt]'] = distance
station_request = requests.get(station_url, params=station_params)
stations = station_request.json()
fuelstation = stations['data']
if len(fuelstation) > 0:
fuelstation.sort(key=lambda k: (k['attributes']['distance_to_star'] is None,
None if k['attributes']['distance_to_star'] is None
else int(k['attributes']['distance_to_star'])))
nearstation = fuelstation[0]['attributes']
print('\rNearest refuel station: ' + nearstation['name'] + ('(Planetary)' if nearstation['is_planetary'] else '')
+ ' in ' + sys1['name'] + ', ' + str(sys1['distance']) + 'LY away, ' + str(nearstation['distance_to_star'])
+ 'Ls from arrival, with ' + nearstation['max_landing_pad_size'] + ' pads')
if (nearstation['max_landing_pad_size'] == 'M'
or nearstation['is_planetary'] == True
or nearstation['distance_to_star'] > maxdistance):
for sys2 in edsm_popsys[i:]:
print('\r{:5.2f}LY'.format(sys2['distance']), end = '', flush=True)
system_params = {'filter[edsm_id:eq]':sys2['id']}
system_request = requests.get(system_url, params=system_params)
nearsys = system_request.json()
station_params = {'filter[system_id:eq]':nearsys['data'][0]['id'], 'filter[has_refuel:eq]':True,
'filter[is_planetary:eq]':False, 'filter[max_landing_pad_size:eq]':'L',
'filter[distance_to_star:lt]':maxdistance}
station_request = requests.get(station_url, params=station_params)
stations = station_request.json()
fuelstationL = stations['data']
if len(fuelstationL) > 0:
fuelstationL.sort(key=lambda k: int(k['attributes']['distance_to_star']))
nearstationL = fuelstationL[0]['attributes']
print('\rNearest large pad orbital station: ' + nearstationL['name'] + ' in ' + sys2['name'] + ', '
+ str(sys2['distance']) + 'LY away, ' + str(nearstationL['distance_to_star']) + 'Ls from arrival')
return
return
print('No stations found (did you make a typo?)')
return
def getNearestRearm(system, exclude = False, pad = None, horizons = True, distance = None):
if distance: maxdistance = max(distance,max_dist)
else: maxdistance = max_dist
edsm_params = {'systemName':system, 'radius':50, 'showPermit':1,
'showInformation':1, 'showId':1}
edsm_req = requests.get(edsm_url, params=edsm_params)
edsm_systems = edsm_req.json()
edsm_popsys = [x for x in edsm_systems if x['information'] != []
and x['requirePermit'] == False]
edsm_popsys.sort(key=lambda k: float(k['distance']))
if exclude: edsm_popsys = edsm_popsys[1:]
for i, sys1 in enumerate(edsm_popsys):
print(sys1['distance'], end='LY\r', flush=True)
system_params = {'filter[edsm_id:eq]':sys1['id']}
system_request = requests.get(system_url, params=system_params)
nearsys = system_request.json()
if len(nearsys['data'])==0: continue
station_params = {'filter[system_id:eq]':nearsys['data'][0]['id'],
'filter[has_rearm:eq]':True}
if pad: station_params['filter[max_landing_pad_size:eq]'] = pad
if not horizons: station_params['filter[is_planetary:eq]'] = False
if distance: station_params['filter[distance_to_star:lt]'] = distance
station_request = requests.get(station_url, params=station_params)
stations = station_request.json()
fuelstation = stations['data']
if len(fuelstation) > 0:
fuelstation.sort(key=lambda k: (k['attributes']['distance_to_star'] is None,
None if k['attributes']['distance_to_star'] is None
else int(k['attributes']['distance_to_star'])))
nearstation = fuelstation[0]['attributes']
print('Nearest restock station: ' + nearstation['name'] + ('(Planetary)' if nearstation['is_planetary'] else '')
+ ' in ' + sys1['name'] + ', ' + str(sys1['distance']) + 'LY away, ' + str(nearstation['distance_to_star'])
+ 'Ls from arrival, with ' + nearstation['max_landing_pad_size'] + ' pads')
if (nearstation['max_landing_pad_size'] == 'M'
or nearstation['is_planetary'] == True
or nearstation['distance_to_star'] > maxdistance):
for sys2 in edsm_popsys[i:]:
print(sys2['distance'], end='LY\r', flush=True)
system_params = {'filter[edsm_id:eq]':sys2['id']}
system_request = requests.get(system_url, params=system_params)
nearsys = system_request.json()
station_params = {'filter[system_id:eq]':nearsys['data'][0]['id'], 'filter[has_rearm:eq]':True,
'filter[is_planetary:eq]':False, 'filter[max_landing_pad_size:eq]':'L',
'filter[distance_to_star:lt]':maxdistance}
station_request = requests.get(station_url, params=station_params)
stations = station_request.json()
fuelstationL = stations['data']
if len(fuelstationL) > 0:
fuelstationL.sort(key=lambda k: int(k['attributes']['distance_to_star']))
nearstationL = fuelstationL[0]['attributes']
print('Nearest large pad orbital station: ' + nearstationL['name'] + ' in ' + sys2['name'] + ', '
+ str(sys2['distance']) + 'LY away, ' + str(nearstationL['distance_to_star']) + 'Ls from arrival')
return
return
print('No stations found (did you make a typo?)')
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment