summaryrefslogtreecommitdiff
path: root/ircbus.py
diff options
context:
space:
mode:
Diffstat (limited to 'ircbus.py')
-rw-r--r--ircbus.py54
1 files changed, 54 insertions, 0 deletions
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