Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import psycopg2
  2. import networkx
  3.  
  4. conn = psycopg2.connect(host="localhost",user="eve",password="eve",database="eve")
  5.  
  6. cursor = conn.cursor()
  7.  
  8. def getSolarSystemName(solarSystemID):
  9.     cursor.execute("select solarSystemName from mapSolarSystems where solarSystemID = %s;",(solarSystemID,))
  10.     row = cursor.fetchone()
  11.     result = row[0]
  12.     return result
  13.  
  14. def getSolarSystemID(solarSystemName):
  15.     cursor.execute("select solarSystemID from mapSolarSystems where solarSystemName = %s;",(solarSystemName,))
  16.     row = cursor.fetchone()
  17.     result = row[0]
  18.     return result
  19.  
  20. g = networkx.Graph()
  21. cursor.execute("select fromSolarSystemID, toSolarSystemID from mapSolarSystemJumps")
  22. for row in cursor:
  23.     g.add_edge(row[0],row[1])
  24.  
  25. jitaid = getSolarSystemID("Jita")
  26. rensid = getSolarSystemID("Rens")
  27. shortestpath = networkx.shortest_path(g,jitaid,rensid)
  28. for node in shortestpath:
  29.     print(getSolarSystemName(node))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement