It looks like you're new here. If you want to get involved, click one of these buttons!
from BlinkyTape import BlinkyTape
from time import sleep
import simplejson, urllib, sys, os, time
bb = BlinkyTape('/dev/tty.usbmodem1441')
bingkey = 'put your bing maps API key here' # <---- won't work without one! You'll need to get a Bing Maps API key, they are free within reasonable limits for personal/educational use
def blink(driving_time,desired):
lights = []
for x in range(60):
if x < driving_time:
rgb = 0,255,0 #green
if driving_time > desired:
rgb = 255,0,0 #red
lights.append(rgb)
else:
rgb = 0,0,0
lights.append(rgb)
for d in range(60*5): #lazy, but keeps the lights on for 5 minutes before requesting more traffic/map data
time.sleep(1)
for x in lights:
bb.sendPixel(x[0],x[1],x[2])
bb.show()
def travel(origin,destination,desired,runtime):
url = "http://dev.virtualearth.net/REST/V1/Routes?wp.0={0}&wp.1={1}&optmz=timeWithTraffic&key={2}".format(str(origin),str(destination),str(bingkey))
runfor = int(runtime / 5)
for i in range(runfor):
result = simplejson.load(urllib.urlopen(url))
driving_time = round(result['resourceSets'][0]['resources'][0]['travelDuration']/60.0)
print "Current travel time is: %s minutes" % (int(driving_time))
if driving_time < float(desired):
os.system('say GTFO') #Mac OSX method to read output aloud, this one says 'go home' in Southern
else:
shittosay = 'say "travel time is %s minutes"' % (int(driving_time)) #handy for when away from my desk
os.system(shittosay)
route = result['resourceSets'][0]['resources'][0]['routeLegs'][0]['itineraryItems']
for i in route:
for i in i['details']:
if i.has_key('names'):
print '%-20s: %-100s' % (i['maneuverType'],i['names'][0])
blink(driving_time,desired)
travel('201 Poplar Ave, Memphis, TN','W Valleywood Dr, Collierville, TN',15,60)
Comments