Skip to content

Instantly share code, notes, and snippets.

@davidgillen
Created October 15, 2014 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidgillen/193275a9c59d6cb6e38b to your computer and use it in GitHub Desktop.
Save davidgillen/193275a9c59d6cb6e38b to your computer and use it in GitHub Desktop.
Query dublin bus to get the times for a specific bus number at a certain stop. e.g. python busTimes.php 4 327
import argparse
import urllib2
import datetime
from bs4 import BeautifulSoup
# Get our arguments
parser = argparse.ArgumentParser()
parser.add_argument("busNumber")
parser.add_argument("stopNumber")
args = parser.parse_args()
busNumber = args.busNumber
stopNumber = args.stopNumber
times = 'http://www.dublinbus.ie/en/RTPI/Sources-of-Real-Time-Information/?searchtype=view&searchquery=' + stopNumber
soup = BeautifulSoup(urllib2.urlopen(times).read())
table = soup.find('table', attrs={'id': 'rtpi-results'})
rows = table.find_all('tr', {'class': ['even','odd']})
output = datetime.datetime.today().strftime('%H:%M:%S %d/%m/%Y,')
for row in rows:
cols = row.find_all('td')
if cols[0].find(text=True).strip() == busNumber:
output += cols[2].find(text=True).strip() + ","
print output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment