-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathpopulate_database.py
More file actions
35 lines (24 loc) · 841 Bytes
/
populate_database.py
File metadata and controls
35 lines (24 loc) · 841 Bytes
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
import query_database
import json
def readJson():
filename = "train-network.json"
with open(filename, "r") as file:
return json.load(file)
def populateStations(stations):
for station in stations:
id = station["id"]
name = station["name"]
latitude = float(station["latitude"])
longitude = float(station["longitude"])
query_database.createStation(id, name, latitude, longitude)
def populateLines(lines):
for line in lines:
lineName = line["name"]
query_database.createLine(lineName)
for stationId in line["stations"]:
query_database.createConnection(stationId, lineName)
jsonRead = readJson()
stations = jsonRead["stations"]
lines = jsonRead["lines"]
populateStations(stations)
populateLines(lines)