-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_db.py
48 lines (40 loc) · 1.15 KB
/
load_db.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
from pymongo import MongoClient
import csv
import json
client = MongoClient('localhost:27017')
db = client.AircraftData
# icao,regid,mdl,type,operator
def add_to_db(row):
icao, regid, mdl, typ, operator = row
try:
db.Registration.insert_one(
{
"icao": icao,
"regid": regid,
"mdl": mdl,
"type": typ,
"operator": operator
})
except Exception as e:
print(str(e))
def load_aircrafts():
print('Loading aircraft data into database...')
with open('aircraft_db.csv', 'r') as f:
reader = csv.reader(f)
reader.next()
for row in reader:
add_to_db(row)
print('Done')
def load_airport_tz():
print('Loading airport timezones into database...')
with open('airports_tz.json', 'r') as f:
airport_tzs = json.loads(f.read())
for key in airport_tzs.keys():
try:
db.AirportTZ.insert_one(airport_tzs[key])
except Exception as e:
print(str(e))
print('Done')
if __name__ == '__main__':
load_aircrafts()
load_airport_tz()