Skip to content

Instantly share code, notes, and snippets.

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