forked from manhtai/vietbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_to_mongo.py
31 lines (24 loc) · 860 Bytes
/
data_to_mongo.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
import json
from pymongo import GEOSPHERE
from app import mongo
#############################################################################
# Import JSON data to MongoDB database
#
# - bus_stops: for querying near bus stops
# - bus_routes: just for getting data from mongodb
#############################################################################
def bus_stops_to_mongo():
with open('app/data/data_stops.json', 'r') as f:
bus_stop = json.load(f)
mongo.db.stops.drop()
for b in bus_stop:
mongo.db.stops.insert(b)
mongo.db.stops.ensure_index([("loc", GEOSPHERE)])
def bus_routes_to_mongo():
mongo.db.routes.drop()
with open('app/data/data_routes.json', 'r') as f:
routes = json.load(f)
mongo.db.routes.insert(routes)
if __name__ == "__main__":
bus_stops_to_mongo()
bus_routes_to_mongo()