Created
September 23, 2018 17:34
-
-
Save dohvis/214bd40be6c41572ce7c647d099ce6da to your computer and use it in GitHub Desktop.
버스 정류장 시간대별 승하차 인원 분석
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from requests import post | |
import pymongo | |
import sys | |
# 8100: 234000878 | |
# 8110: 204000082 | |
# m4102: 234001159 | |
def get_buses(bus_no): | |
bus_dic = {"b8100": 234000878, "b8110": 204000082, "m4102": 234001159} | |
user = "" | |
passwd = "" | |
db = "" | |
client = pymongo.MongoClient('mongodb://{}:{}@127.0.0.1:27017/{}'.format(user, passwd, db)) | |
db = client.busDB | |
url = "http://www.gbis.go.kr/gbis2014/schBusAPI.action" | |
route_id = bus_dic[bus_no] | |
data = post(url, data={"cmd": "searchRouteJson", "routeId": route_id}).json() | |
buses = [] | |
for bus in data["result"]["realTime"]["list"]: | |
bus.update(crawled_at=datetime.now()) | |
buses.append(bus) | |
return db, buses |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment