Skip to content

Instantly share code, notes, and snippets.

@igrr
Forked from grafuls/idos.py
Last active July 13, 2021 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrr/2ddbe3716e8551429873eed381692a1c to your computer and use it in GitHub Desktop.
Save igrr/2ddbe3716e8551429873eed381692a1c to your computer and use it in GitHub Desktop.
python script for getting time left for next bus with idos(Brno)
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