-
Notifications
You must be signed in to change notification settings - Fork 0
/
njtransit.py
35 lines (29 loc) · 848 Bytes
/
njtransit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from HTMLParser import HTMLParser
import requests
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
def get_data(self):
return ''.join(self.fed)
def strip_tags(html):
s = MLStripper()
s.feed(html)
return s.get_data()
def main():
url = "http://mybusnow.njtransit.com/bustime/wireless/html/eta.jsp?route=166&id=26229&showAllBusses=off"
req = requests.get(url)
req = strip_tags(req.text)
req = req.replace("\r\n", "")
req = req.replace("\t\t\t\t", " ")
start = req.find("To 166T")
end = start + req[start:].find("MIN") + 3
output = req[start:end].replace("\t\t\t", ' ')
if output == '':
print "No bus!"
else:
print output
if __name__ == "__main__":
main()