From c66d1e5d1fdc48641743e953e0134a5318459a18 Mon Sep 17 00:00:00 2001 From: Cormac Morris Date: Mon, 9 Nov 2015 13:40:59 +0000 Subject: First instance of script --- cleanupbusinfo.sh | 25 +++++++++++++++++++++++++ ircbus.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ updatebusinfo.py | 14 ++++++++++++++ 3 files changed, 93 insertions(+) create mode 100755 cleanupbusinfo.sh create mode 100644 ircbus.py create mode 100644 updatebusinfo.py 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 '/Dep/d' "$n" + sed -i '/direction arrow/d' Dep/d' "$n" + sed -i '/<\/span><\/td>/d' "$n" + sed -i '/.*<\/span>/d' "$n" + sed -i '/<\/tr>, /d' "$n" + sed -i '/<\/tr>, /d' "$n" + sed -i '//d' "$n" + sed -i '/.*<\/span><\/td>/d' "$n" + sed -i '/    <\/td>/d' "$n" + sed -i '/ <\/td>/d' "$n" + sed -i 's///g' "$n" + sed -i 's/<\/td>//g' "$n" + sed -i 's///g' "$n" + sed -i 's/<\/span><\/th>//g' "$n" + sed -i 's/

//g' "$n" + sed -i 's/<\/h2>//g' "$n" + sed -i 's///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 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 + + -- cgit v1.2.3