-
-
Save igrr/2ddbe3716e8551429873eed381692a1c to your computer and use it in GitHub Desktop.
python script for getting time left for next bus with idos(Brno)
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 bs4 import BeautifulSoup as bs | |
from dateutil import parser | |
from datetime import datetime | |
import requests | |
import re | |
# search for all buses leaving from one station in any direction | |
URL = 'http://jizdnirady.idnes.cz/brno/odjezdy/?f=cervinkova&fc=302003&lng=E&submit=true' | |
def fetch_source(source_url): | |
response = requests.get(source_url) | |
return response.text | |
if __name__ == '__main__': | |
idos_response = fetch_source(URL) | |
idos_soup = bs(idos_response, features="html.parser") | |
idos_times = idos_soup.findAll('table', {'class':re.compile(r'departures-table*')}) | |
results = idos_times[0].findAll('tr', {'class':re.compile(r'dep-row-first*')}) | |
for result in results: | |
res = result.findAll('td', {'class':re.compile(r'departures-table__cell*')}) | |
timer = parser.parse(res[2].text) - datetime.now() | |
if parser.parse(res[2].text) > datetime.now(): | |
line = result.findAll('span', {'class':re.compile(r'code')})[0].findAll('h3')[0].text.strip() | |
print('IN:', timer.seconds / 60, 'minutes ->', res[2].text.strip(), "line: ", line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment