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