-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportMap.py
50 lines (43 loc) · 1.38 KB
/
importMap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import networkx as nx
import pickle, psycopg2
f = open('databaseLogin.txt')
host = f.readline().strip()
db = f.readline().strip()
user = f.readline().strip()
password = f.readline().strip()
f.close()
conn = psycopg2.connect(host=host, database=db, user=user, password=password)
cur = conn.cursor()
cur.execute("""
SELECT systems."solarSystemID" as system,
systems."solarSystemName" as "systemName",
systems."constellationID" as constellation,
systems."regionID" as region,
systems.security as security,
systems."securityClass" as "securityClass",
constellations."constellationName" as "constellationName",
regions."regionName" as "regionName"
FROM public."mapSolarSystems" AS systems
LEFT JOIN public."mapConstellations" as constellations
ON constellations."constellationID"=systems."constellationID"
LEFT JOIN public."mapRegions" as regions
ON regions."regionID"=systems."regionID";
""")
d = cur.description
eveMap = nx.Graph()
sysID = {}
for row in cur:
eveMap.add_node(row[0], {c.name: value for c, value in zip(d[1:], row[1:])})
sysID[row[1]] = row[0]
cur.execute("""
SELECT "fromSolarSystemID", "toSolarSystemID"
FROM public."mapSolarSystemJumps"
WHERE "fromSolarSystemID"<"toSolarSystemID";
""")
for row in cur:
eveMap.add_edge(row[0], row[1])
cur.close()
conn.close()
f = open("eveMap.pickle", "wb")
pickle.dump(eveMap, f)
f.close()