Skip to content

Instantly share code, notes, and snippets.

@nolageek
Created May 11, 2015 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolageek/f445a57b7de41df6f331 to your computer and use it in GitHub Desktop.
Save nolageek/f445a57b7de41df6f331 to your computer and use it in GitHub Desktop.
wmata times for daydream bbs
from pywmata import Wmata
from blessed import Terminal
import os
import dd
import sys
t = Terminal()
api = Wmata("xxxxxxxxxxxxxxxxxxxx")
if (dd.initdoor(sys.argv[1])==0):
print "Ugh. Run me from DD\n"
sys.exit(-1)
else:
def listLines():
name = str(dd.getvar(dd.USER_ACCOUNT_ID))
dd.sendstring(name)
dd.pause()
os.system('clear')
dd.typefile("wmata",dd.TYPE_MAKE)
dd.sendstring(t.bold("\r\nDD/WMATA by nolageek.\r\n\r\n"))
lines = api.lines()
n = len(lines)
for i in range(0,n):
dd.sendstring(" " + t.bold_white(str(i+1) + ": ") + getColor(lines[i]["LineCode"],lines[i]['DisplayName']) + " ")
dd.sendstring(t.bold_magenta("\r\n\r\n Please select a line, 'Q' to quit"))
dd.sendstring(t.bold_white(": "))
inp = dd.prompt("",2,dd.PROMPT_NOCRLF)
if inp is not None and inp.isdigit() and int(inp) < n+1:
inp = int(inp)
color = lines[inp-1]["LineCode"]
listStations(color)
elif inp.upper() == u'Q':
sys.exit("\r\nReturning to the BBS...")
else:
dd.sendstring("\r\nInvalid selection!")
dd.pause()
listLines()
def listStations(color):
os.system('clear')
dd.typefile("wmata",dd.TYPE_MAKE)
stations = api.stations(color)
n = len (stations)
col = len(stations)/3
for i in range (0,col):
dd.sendstring(t.move(13+(i+1),1) + t.bold_magenta(str(i+1)) + ": " + getColor(color,stations[i]["Name"]) + "\r\n")
for i in range (col,n-col):
dd.sendstring(t.move(13+(i-(col-1)),26) + t.bold_magenta(str(i+1)) + ": " + getColor(color,stations[i]["Name"]) + "\r\n")
for i in range (n-col,len (stations)):
dd.sendstring(t.move(13+(i-((n-col)-1)),51) + t.bold_magenta(str(i+1)) + ": " + getColor(color,stations[i]["Name"]) + "\r\n")
##dd.sendstring("\033[0;37m" + str(i+1) + ": " + getColor(color,stations[i]["Name"]) + "\r\n")
dd.sendstring(t.move(24,1) + t.bold_blue("Select Station, 'Q' to quit: "))
inp = dd.prompt("",3,dd.PROMPT_NOCRLF)
if inp is not None and inp.isdigit() and int(inp) < n+1:
inp = int(inp)
station = stations[inp-1]["Code"]
listTimes(station)
elif inp.upper() == u'Q':
listLines()
else:
dd.sendstring(t.red_reverse("Invalid Station!") + "\r\n")
dd.pause()
listStations(color)
def listTimes(station):
os.system('clear')
dd.typefile("wmata",dd.TYPE_MAKE)
times = api.rail_predictions(station)
n = len(times)
if n == 0:
# name = str(times[0]["LocationName"])
dd.sendstring(t.red_reverse("\r\n No sign data is available for that station (" + station + ")"))
dd.pause()
listLines()
else:
name = str(times[0]["LocationName"])
# os.system('clear')
dd.sendstring(t.bright_red("STATIONS TIMES FOR " + name.upper()))
dd.sendstring("\r\nLN CAR DESTINATION MIN\r\n")
n = len(times)
if n is not None:
for i in range(0,n):
dd.sendstring(getColor(times[i]["Line"],times[i]["Line"]) + " " + str(times[i]["Car"]) + " " + str(times[i]["Destination"]).upper() + " " + str(times[i]["Min"]) + "\r\n$
dd.pause()
listLines()
def getColor(line,txt):
if line == "RD":
line = t.bold_red(txt)
elif line == "GR":
line = t.green(txt)
elif line == "BL":
line = t.cyan(txt)
elif line == "SV":
line = t.white(txt)
elif line == "YL":
line = t.bold_yellow(txt)
elif line == "OR":
line = t.yellow(txt)
else:
line = t.white(txt)
return line
listLines()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment