snarf.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. import requests
  3. import sqlite3
  4. import time
  5. con = sqlite3.connect('new_eden.db')
  6. cur = con.cursor()
  7. query_regions = "https://esi.evetech.net/v1/universe/regions/"
  8. query_constellations = "https://esi.evetech.net/v1/universe/constellations/"
  9. query_systems = "https://esi.evetech.net/v4/universe/systems/"
  10. query_gates = "https://esi.evetech.net/v1/universe/stargates/"
  11. # 11000000
  12. regions = requests.get(query_regions).json()
  13. for region_id in regions:
  14. try:
  15. region = requests.get(query_regions+str(region_id)).json()
  16. except:
  17. time.sleep(30)
  18. print("Region: "+region['name'])
  19. for constellation_id in region['constellations']:
  20. try:
  21. constellation = requests.get(query_constellations+str(constellation_id)).json()
  22. except:
  23. time.sleep(30)
  24. for system_id in constellation["systems"]:
  25. try:
  26. system = requests.get(query_systems+str(system_id)).json()
  27. except:
  28. time.sleep(30)
  29. # print(str(system['system_id']), system['name'], str(constellation['constellation_id']), constellation['name'], str(region['region_id']), region['name'])
  30. cur.execute("INSERT INTO systems VALUES (?,?,?,?,?,?)", (system['system_id'], system['name'], constellation['constellation_id'], constellation['name'], region['region_id'], region['name']))
  31. try:
  32. if len(system["stargates"]) > 0:
  33. for gate in system["stargates"]:
  34. gate_info = requests.get(query_gates+str(gate)).json()
  35. # print(system["system_id"], gate_info["destination"]["system_id"])
  36. cur.execute("INSERT INTO gates VALUES (?,?)",(system["system_id"],gate_info["destination"]["system_id"]))
  37. except KeyError:
  38. pass
  39. con.commit()
  40. time.sleep(1)
  41. time.sleep(10)
  42. con.close()