Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Jason Rutherford
Added: Jun 2, 2019 3:46 PM
Views: 20
  1. import requests
  2.  
  3. def searchSystems(systemName, radius):
  4.  
  5.     for item in getSystems(systemName, radius):
  6.         data = getSystemEstimatedValue(item['name'])
  7.  
  8.         for key in data.keys():
  9.             print(key + ":" + str(data[key]))
  10.  
  11.         print ""
  12.  
  13. def getSystems(systemName, radius):
  14.     requestData = {
  15.         "systemName": systemName,
  16.         "radius": radius
  17.     }
  18.  
  19.     data = requests.get("https://www.edsm.net/api-v1/sphere-systems", requestData)
  20.  
  21.     if data.status_code == 200:
  22.         return data.json()
  23.  
  24.     else:
  25.         raise("request returned bad response code %d" % (data.status_code))
  26.  
  27. def getSystemEstimatedValue(systemName):
  28.  
  29.     requestData = {
  30.         "systemName": systemName
  31.     }
  32.  
  33.     data = requests.get("https://www.edsm.net/api-system-v1/estimated-value", requestData)
  34.  
  35.     if data.status_code == 200:
  36.         return data.json()
  37.  
  38.     else:
  39.         raise ("request returned bad response code %d" % (data.status_code))
  40.  
  41. if __name__ == "__main__":
  42.     searchSystems("Colonia", "100")
  43.  
Comments disabled