forked from nicolewhite/neo4j-flights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_lookups.py
37 lines (27 loc) · 853 Bytes
/
import_lookups.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
from csv_things import import_csv_to_dict
from py2neo import neo4j
from batch_upload import batch_upload
graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
batch = neo4j.WriteBatch(graph)
data = import_csv_to_dict('L_UNIQUE_CARRIERS.csv', headers = True)
query = """
MATCH (c:Carrier {abbr:UPPER({Code})})
SET c.name = UPPER({Description})
"""
batch_upload(batch, data, query)
data = import_csv_to_dict('L_AIRPORT_ID.csv', headers = True)
# Split on colon to get only the airport name.
for d in data:
text = d['Description']
text = text.split(":")
if(len(text) == 2):
city, airport = text
else:
airport = text[0]
airport = airport.strip()
d['Description'] = airport
query = """
MATCH (a:Airport {id:TOINT({Code})})
SET a.name = UPPER({Description})
"""
batch_upload(batch, data, query)