From ab7f0dac0ad052fc84290af79065bd7fb826ba35 Mon Sep 17 00:00:00 2001 From: Cormac Morris Date: Fri, 13 Nov 2015 11:44:58 +0000 Subject: Updated script to supports buses that use letters and numbers together. Also added support for using more than one word to search bus stop name. --- ircbus.py | 22 ++++++++++++---------- updatebusinfo.py | 9 ++++++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ircbus.py b/ircbus.py index bd947cb..559e932 100644 --- a/ircbus.py +++ b/ircbus.py @@ -11,14 +11,13 @@ def split(s): return filter(None, re.split(r'(\d+)', s)) ircinput = sys.stdin.read().lower() -input = split(ircinput) -stop = input[0].strip() -bus = input[1].strip() -bound = input[2].strip() -busfile = bus + '.txt' +input = ircinput.split() +stop = re.split('[\s][(\d)x]', ircinput)[0] +bus = input[-2].strip() +bound = input[-1].strip() +busfile = bus.upper() + '.txt' now = datetime.now() today = now.strftime("%A").lower() -boundsearch = (bound + " - " + today) datelist = [] if bound == "inbound": @@ -26,9 +25,14 @@ if bound == "inbound": else: endbound = "inbound" -if now.isoweekday() in range(1, 6): - today = "monday-friday" +if now.isoweekday() in range(1, 5): + day = "monday-friday" +elif now.isoweekday() == 6: + day = "saturday" +else: + day = "sunday" +boundsearch = (bound + " - " + day) with open(busfile, "r") as busread: for line in busread: line = line.lower() @@ -39,8 +43,6 @@ with open(busfile, "r") as busread: if stop in linelw: previousline = line.strip() break - for line in busread: - break for line in busread: line = line.strip() if ":" in line: diff --git a/updatebusinfo.py b/updatebusinfo.py index 3663d24..ffc38fc 100644 --- a/updatebusinfo.py +++ b/updatebusinfo.py @@ -2,13 +2,16 @@ import sys from bs4 import BeautifulSoup import urllib2 -for id in ('1', '1A', '1G', '2', '2A', '3', '4', '5', '7', '7a', '8', '9', '12', '13', '15', '16', '19', '21', '22', 'x22', '23', '28'): - bus = '/' + id + '/FALSE' +for id in ('1', '1A', '1G', '2', '2A', '3', '4', '5', '7', '7a', '8', '9', '12', '13', '15', '16', '19', '21', '22', 'X22', '23', '28'): + if id == '7a': + bus = '/' + id + '/FALSE' + else: + bus = '/' + id.upper() + '/FALSE' url = 'http://libertybus.je/routes_times/timetables' + bus page = urllib2.urlopen(url) soup = BeautifulSoup(page) table = soup.findAll(['tr', 'h2']) - sys.stdout = open(id + '.txt', 'w') + sys.stdout = open(id.upper() + '.txt', 'w') print table -- cgit v1.2.3