Last active
July 13, 2021 19:25
-
-
Save grafuls/91b3ef3e89a32ed9087f 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 BeautifulSoup 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) | |
idos_times = idos_soup.findAll('table', {'class':re.compile(ur'results*')}) | |
results = idos_times[0].findAll('tr', {'class':re.compile(ur'septr*')}) | |
for result in results: | |
res = result.findAll('td', {'class':re.compile(ur'datedt*')}) | |
timer = parser.parse(res[0].text) - datetime.now() | |
if parser.parse(res[0].text) > datetime.now(): | |
line = result.findAll('a', {'title':re.compile(ur'bus')}) | |
print 'IN:', timer.seconds / 60, 'minutes ->', res[0].text, "-> bus:", line[0].text[-2:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment