diff options
author | Cormac Morris <cormacmorris@hotmail.com> | 2015-11-09 13:40:59 +0000 |
---|---|---|
committer | Cormac Morris <cormacmorris@hotmail.com> | 2015-11-09 13:40:59 +0000 |
commit | c66d1e5d1fdc48641743e953e0134a5318459a18 (patch) | |
tree | 8ff49604dd6db5cdb265d0c30598bc6aa4be277c |
First instance of script
-rwxr-xr-x | cleanupbusinfo.sh | 25 | ||||
-rw-r--r-- | ircbus.py | 54 | ||||
-rw-r--r-- | updatebusinfo.py | 14 |
3 files changed, 93 insertions, 0 deletions
diff --git a/cleanupbusinfo.sh b/cleanupbusinfo.sh new file mode 100755 index 0000000..398b1a7 --- /dev/null +++ b/cleanupbusinfo.sh @@ -0,0 +1,25 @@ +for n in "$@" ; do + sed -i '/<td class="StopHeader"><span>Dep/d' "$n" + sed -i '/<td class="StopHeader"><img alt="direction arrow/d' "$n" + sed -i '/<td class="StopHeader"><span>Dep/d' "$n" + sed -i '/<td class="StopHeader"><span><\/span><\/td>/d' "$n" + sed -i '/<th><span>.*<\/span>/d' "$n" + sed -i '/<\/tr>, <tr>/d' "$n" + sed -i '/<\/tr>, <tr>/d' "$n" + sed -i '/<!--<td><span>Dep<\/span><\/td> -->/d' "$n" + sed -i '/<td><span>.*<\/span><\/td>/d' "$n" + sed -i '/<td class=.*> <\/td>/d' "$n" + sed -i '/<td class="end-row"> <\/td>/d' "$n" + sed -i 's/<td>//g' "$n" + sed -i 's/<\/td>//g' "$n" + sed -i 's/<th class="StopHeader"><span>//g' "$n" + sed -i 's/<\/span><\/th>//g' "$n" + sed -i 's/<h2>//g' "$n" + sed -i 's/<\/h2>//g' "$n" + sed -i 's/<tr>//g' "$n" + sed -i 's/\[//g' "$n" + sed -i 's/<\/tr>, //g' "$n" + sed -i 's/<\/tr>, Your feedback]//g' "$n" + sed -i 's/<\/tr>, //g' "$n" + sed -i '/^.\{,3\}$/d' "$n" +done diff --git a/ircbus.py b/ircbus.py new file mode 100644 index 0000000..bd947cb --- /dev/null +++ b/ircbus.py @@ -0,0 +1,54 @@ +import re +import sys +import optparse +from datetime import datetime +from operator import itemgetter + +parser = optparse.OptionParser(usage="!bus <stop> <number> <inbound/outbound> i.e: !bus Liberation 15 Outbound") +parser.parse_args() + +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' +now = datetime.now() +today = now.strftime("%A").lower() +boundsearch = (bound + " - " + today) +datelist = [] + +if bound == "inbound": + endbound = "outbound" +else: + endbound = "inbound" + +if now.isoweekday() in range(1, 6): + today = "monday-friday" + +with open(busfile, "r") as busread: + for line in busread: + line = line.lower() + if boundsearch in line: + break + for line in busread: + linelw = line.lower() + if stop in linelw: + previousline = line.strip() + break + for line in busread: + break + for line in busread: + line = line.strip() + if ":" in line: + date = datetime.strptime(line, "%H:%M").time() + if date > now.time(): + datelist.append(date.strftime("%H:%M" + " ")) + else: + datelist.append("\n") + liststring = ''.join(datelist) + sys.stdout.write("The next " + bound + " #" + bus + " buses at " + previousline + " " + "are: " + liststring) + break diff --git a/updatebusinfo.py b/updatebusinfo.py new file mode 100644 index 0000000..3663d24 --- /dev/null +++ b/updatebusinfo.py @@ -0,0 +1,14 @@ +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' + 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') + print table + + |