import requests from bs4 import BeautifulSoup from models.trains.train import Train from common.database import Database def daterange(start_date, end_date): for n in range(int((end_date - start_date).days)): yield start_date + timedelta(n) start_date = date(2018, 1, 10) end_date = date(2018, 1, 20) Database.initialize() Trains = Train.all() for single_date in daterange(start_date, end_date): date = single_date.strftime("%Y-%m-%d") print(date) for train in Trains[1:]: train._id = train._id.zfill(5) print(train._id) request = requests.get("https://railenquiry.in/runningstatus/ " + train._id + "/" + date) content = request.content soup = BeautifulSoup(content, "html.parser") [s.extract() for s in soup('a')] [s.extract() for s in soup('input')] [s.extract() for s in soup('label')] [s.extract() for s in soup('small')]
def get_timetable(train_no): train_class = Train.get_by_id(train_no) stations = TimeTable.get_stations_by_train(train_no) return render_template("timetable.html", stations=stations, train_class=train_class)