-
Notifications
You must be signed in to change notification settings - Fork 0
/
infoMiniRunner.py
4398 lines (2042 loc) · 102 KB
/
infoMiniRunner.py
1
import configimport datetimeimport osimport gttsfrom requests.packages.urllib3.exceptions import InsecureRequestWarningfrom requests.exceptions import ConnectionErrorimport Adafruit_CharLCD as LCDimport twitterimport urllib2import jsonimport timeimport requestsimport unittestimport socketimport fcntlimport structfrom pymbta import RedLinefrom nextbus import *requests.packages.urllib3.disable_warnings(InsecureRequestWarning)lifxHeaders = { "Authorization": "Bearer %s" % config.lifxAPI, }api = twitter.Api(consumer_key=config.twitterAPIconsumerKey, consumer_secret=config.twitterAPIconsumerSecret, access_token_key=config.twitterAPIaccessTokenKey, access_token_secret=config.twitterAPIaccessTokenSecret,)print api.VerifyCredentials()os.environ["MBTA_API_KEY"] = config.mbtaAPImode = 10oldMode = 10colour_x = ''status_text = ''final_status = ''final_status_with_x = ''old_status = ''old_status_without_x = ''mitString = ''mbtaString = ''printstring = ''hasTalked = False## INITIALISE LCD USING PINSlcd = LCD.Adafruit_CharLCDPlate()os.system("amixer cset numid=3 1")os.system("amixer cset numid=1 -- 100%")## CREATE INFINITE LOOP FOR CATCHING BUTTONSintBrightness = '100'lifxKelvin = 100currentColourString = 'Up for colour C 'nextColourString = 'Up for colour C 'nextLifxKelvin = 100nextRed = 0nextGreen = 0nextBlue = 0talkingMode = 1time.sleep(2.0)lcd.set_color(1,1,0)time.sleep(0.5)lcd.set_color(1,0,0)time.sleep(0.5)lcd.set_color(1,0,1)time.sleep(0.5)lcd.set_color(0,1,1)time.sleep(0.5)lcd.set_color(1,1,1)time.sleep(0.5)lcd.set_color(0,1,0)time.sleep(0.5)lcd.set_color(0,0,1)time.sleep(4.0)sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)ipLo = socket.inet_ntoa(fcntl.ioctl( sock.fileno(), 0x8915, #SIOCGIFADDR struct.pack('256s', 'lo'[:15]))[20:24])print ipLoipWlan0 = socket.inet_ntoa(fcntl.ioctl( sock.fileno(), 0x8915, #SIOCGIFADDR struct.pack('256s', 'wlan0'[:15]))[20:24])print ipWlan0lcd.message(ipLo + '\n' + ipWlan0)os.system("aplay /home/pi/infoMini/one_tone.wav")print "check 1"while True: ## TOGGLE TALKING MODE if (mode == 100): if talkingMode == 0: talkingMode = 1 lcd.clear() lcd.message("Talking mode on \nReminder mode on") tts = gtts.gTTS(text="Talking mode and reminder mode. On. ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") elif talkingMode == 2: talkingMode = 0 lcd.clear() lcd.message("Talking mode off\nRemindr mode off") tts = gtts.gTTS(text="Talking mode and reminder mode. Off. ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") elif talkingMode == 1: talkingMode = 2 lcd.clear() lcd.message("Talking mode off\nReminder mode on") tts = gtts.gTTS(text="Reminder mode. On. ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 10 ## CHECK FOR EMERGENCY MESSAGES if (mode == 33): now = datetime.datetime.now() print 'checking the weather ' + now.strftime('%H:%M:%S') try: f = urllib2.urlopen('http://api.wunderground.com/api/' + config.weatherAPI + '/alerts/q/MA/Cambridge.json') except urllib2.HTTPError as e: print e json_string = f.read() parsed_json = '' alertsListing = '' try: parsed_json = json.loads(json_string) except ValueError as e: parsed_json = '' try: alertsListing = parsed_json['alerts'] except KeyError as e: alertsListing = '' if len(alertsListing) > 0: pheno = alertsListing[0]['phenomena'] signf = alertsListing[0]['significance'] exprs = alertsListing[0]['expires_epoch'] fullMessage = alertsListing[0]['message'] if (signf == 'W') and (pheno == 'SV' or pheno == 'FA' or pheno == 'FL' or pheno == 'FF' or pheno == 'TO' or pheno == 'BZ') and (fullMessage.find('Somerville') > -1 or fullMessage.find('Cambridge') > -1): warningTitle = '' print exprs print alertsListing[0]['date_epoch'] if (pheno == 'SV') and (signf == 'W'): warningTitle = 'SVR TSTORM WARNG' if ((pheno == 'FA') or (pheno == 'FL')) and (signf == 'W'): warningTitle = 'FLOOD WARNING ' if (pheno == 'FF') and (signf == 'W'): warningTitle = 'FLSH FLOOD WARNG' if (pheno == 'TO') and (signf == 'W'): warningTitle = ' TORNADO WARNING' if (pheno == 'BZ') and (signf == 'W'): warningTitle = 'BLIZZARD WARNING' #expireStamp = datetime.datetime.fromtimestamp(float(exprs)/1000.) #fmt = '%H:%M' #expireTime = expireStamp.strftime(fmt) expireTime = time.strftime('%H:%M', time.localtime(float(exprs))) lcd.clear() lcd.set_color(1,1,0) # YELLOW SAD COLOUR lcd.message(warningTitle + '\n' + ' until ' + expireTime) if (pheno == 'SV') and (signf == 'W'): warningText = 'A sir. veer. thunderstorm. warning. is in effect. for this area until. ' + expireTime if (pheno == 'FF') and (signf == 'W'): warningText = 'A flash flood warning is in effect. for this area until. ' + expireTime if ((pheno == 'FA') or (pheno == 'FL')) and (signf == 'W'): warningText = 'A flood warning is in effect. for this area until. ' + expireTime if (pheno == 'TO') and (signf == 'W'): warningText = 'Take cover now! Take cover now! A tornado warning is in effect. for this area until. ' + expireTime if (pheno == 'BZ') and (signf == 'W'): warningText = 'A blizzard warning is in effect. for this area until. ' + expireTime lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR if pheno != 'BZ': os.system("aplay /home/pi/infoMini/hilo.wav") lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR tts = gtts.gTTS(text=warningText + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR sendBright = { "period": 2, "cycles": 5, "power_on": "true", "persist": "false", "color": "brightness: 0.8", "from_color": "brightness: 0.05" } response = requests.post('https://api.lifx.com/v1/lights/all/effects/pulse', data=sendBright, headers=lifxHeaders) os.system("aplay /home/pi/infoMini/hilo.wav") lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR tts = gtts.gTTS(text=warningText + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(15.0) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(0.2) lcd.set_color(0,0,0) # NO COLOUR time.sleep(0.2) lcd.set_color(1,1,0) # YELLOW SAD COLOUR time.sleep(30.0) print len(alertsListing) print alertsListing #temp_f = parsed_json['current_observation']['temp_f'] #tempString = str(temp_f) + "F " + weather if oldMode == 0: mode = 10 else: mode = oldMode ## LIFX MODES (5-9, 15-19) if (mode == 5) or (mode == 15): print mode if (mode == 15) or ((now.second%59) == 0): response1 = requests.get('https://api.lifx.com/v1/lights/all', headers=lifxHeaders) print "just requested oh no" splitBrightness = str(response1.json()[0]['brightness']*100).split('.') lifxKelvin = str(response1.json()[0]['color']['kelvin']) intBrightness = splitBrightness[0] if intBrightness == '0': currentBrightness = intBrightness + '% ' elif intBrightness == '100': currentBrightness = intBrightness + '%' else: currentBrightness = intBrightness + '% ' thisRed = 1 thisGreen = 1 thisBlue = 1 if int(lifxKelvin) <= 2500: currentColourString = 'Toasty C ' nextColourString = 'Just blue C ' nextLifxKelvin = '9000' thisRed = 1 thisGreen = 0 thisBlue = 0 nextRed = 0 nextGreen = 0 nextBlue = 1 elif int(lifxKelvin) <= 3000: currentColourString = 'Warm C ' nextColourString = 'Toasty C ' nextLifxKelvin = '2500' thisRed = 1 thisGreen = 0 thisBlue = 0 nextRed = 1 nextGreen = 0 nextBlue = 0 elif int(lifxKelvin) <= 3500: currentColourString = 'Neutral C ' nextColourString = 'Warm C ' nextLifxKelvin = '3000' thisRed = 1 thisGreen = 1 thisBlue = 0 nextRed = 1 nextGreen = 0 nextBlue = 0 elif int(lifxKelvin) >= 9000: currentColourString = 'Just blue C ' nextColourString = 'Blue day C ' nextLifxKelvin = '7500' thisRed = 0 thisGreen = 0 thisBlue = 1 nextRed = 0 nextGreen = 0 nextBlue = 1 elif int(lifxKelvin) >= 7500: currentColourString = 'Blue day C ' nextColourString = 'Noontime C ' nextLifxKelvin = '6000' thisRed = 0 thisGreen = 0 thisBlue = 1 nextRed = 0 nextGreen = 1 nextBlue = 1 elif int(lifxKelvin) >= 6000: currentColourString = 'Noontime C ' nextColourString = 'Cool day C ' nextLifxKelvin = '4500' thisRed = 0 thisGreen = 1 thisBlue = 1 nextRed = 0 nextGreen = 1 nextBlue = 1 elif int(lifxKelvin) >= 4500: currentColourString = 'Cool day C ' nextColourString = 'Neutral C ' nextLifxKelvin = '3500' thisRed = 0 thisGreen = 1 thisBlue = 1 nextRed = 1 nextGreen = 1 nextBlue = 0 print "line 01" lifxString = currentColourString + '\n' + 'jfabi ' + currentBrightness + ' X - +' print "line 02" if mode == 15: lcd.clear() print "line 02a" lcd.message(lifxString) print "line 03" lcd.set_color(thisRed,thisGreen,thisBlue) print "line 04" # time.sleep(1.5) # os.system("flite -voice kal16 -t 'The current brightness is" + currentBrightness + "'") mode = 5 buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 82), (LCD.UP, 16), (LCD.DOWN, 10), (LCD.RIGHT, 83) ) for button in buttons: if lcd.is_pressed(button[0]): print "PRESSED" + str(button[0]) print "line 05" if (button[1] == 10): mode = 10 elif button[1] == 82: print "line 06" splitNewBrightness = intBrightness.split('.') intNewBrightness = splitNewBrightness[0] newPrintBrightness = (int(intNewBrightness) - 6) newBrightness = newPrintBrightness/100.0 if newBrightness < 0.0: newBrightness = 0.0 print "line 07" print newBrightness print "line 08" sendBright = { "brightness": newBrightness, "power": "on" } print "line 09" print sendBright response = requests.put('https://api.lifx.com/v1/lights/all/state', data=sendBright, headers=lifxHeaders) print "line 10" print response mode = 5 print "line 11" intBrightness = str(newPrintBrightness).split('.')[0] if intBrightness == '0': currentBrightness = intBrightness + '% ' elif intBrightness == '100': currentBrightness = intBrightness + '%' else: currentBrightness = intBrightness + '% ' print "line 01b" lifxString = 'Up for colour C ' + '\n' + 'jfabi ' + currentBrightness + ' X - +' print "line 02b" lcd.message(lifxString) elif button[1] == 83: print "line 06" splitNewBrightness = intBrightness.split('.') intNewBrightness = splitNewBrightness[0] newPrintBrightness = (int(intNewBrightness) + 6) newBrightness = newPrintBrightness/100.0 print newBrightness if newBrightness < 0.0: newBrightness = 0.0 print "line 07" print newBrightness print "line 08" sendBright = { "brightness": newBrightness, "power": "on" } print "line 09" print sendBright response = requests.put('https://api.lifx.com/v1/lights/all/state', data=sendBright, headers=lifxHeaders) print "line 10" print response mode = 5 print "line 11" intBrightness = str(newPrintBrightness).split('.')[0] if intBrightness == '0': currentBrightness = intBrightness + '% ' elif intBrightness == '100': currentBrightness = intBrightness + '%' else: currentBrightness = intBrightness + '% ' print "line 01b" lifxString = 'Up for colour C ' + '\n' + 'jfabi ' + currentBrightness + ' X - +' print "line 02b" lcd.message(lifxString) elif (button[1] == 16): lifxString = nextColourString + '\n' + 'jfabi ' + currentBrightness + ' X - +' lcd.clear() lcd.message(lifxString) lcd.set_color(nextRed,nextGreen,nextBlue) send = { "color": "kelvin:" + nextLifxKelvin, "duration": 3.0, } response = requests.put('https://api.lifx.com/v1/lights/all/state', data=send, headers=lifxHeaders) lifxKelvin = nextLifxKelvin time.sleep(1.5) if int(lifxKelvin) <= 2500: nextColourString = 'Just blue C ' nextLifxKelvin = '9000' nextRed = 0 nextGreen = 0 nextBlue = 1 elif int(lifxKelvin) <= 3000: nextColourString = 'Toasty C ' nextLifxKelvin = '2500' nextRed = 1 nextGreen = 0 nextBlue = 0 elif int(lifxKelvin) <= 3500: nextColourString = 'Warm C ' nextLifxKelvin = '3000' nextRed = 1 nextGreen = 0 nextBlue = 0 elif int(lifxKelvin) >= 9000: nextColourString = 'Blue day C ' nextLifxKelvin = '7500' nextRed = 0 nextGreen = 0 nextBlue = 1 elif int(lifxKelvin) >= 7500: nextColourString = 'Noontime C ' nextLifxKelvin = '6000' nextRed = 0 nextGreen = 1 nextBlue = 1 elif int(lifxKelvin) >= 6000: nextColourString = 'Cool day C ' nextLifxKelvin = '4500' nextRed = 0 nextGreen = 1 nextBlue = 1 elif int(lifxKelvin) >= 4500: nextColourString = 'Neutral C ' nextLifxKelvin = '3500' nextRed = 1 nextGreen = 1 nextBlue = 0 ## WEATHER MODE (4) if (mode == 4) or (mode == 14): now = datetime.datetime.now() if (now.second == 59 and now.second % 10 == 0) or (mode == 14): f = urllib2.urlopen('http://api.wunderground.com/api/' + config.weatherAPI + '/conditions/q/pws:KMACAMBR9.json') json_string = f.read() parsed_json = '' try: parsed_json = json.loads(json_string) except ValueError as e: print 'ERROR was registered with ValueError' print e parsed_json = '' weather = '' temp_f = 0 temp_c = 0 feel_f = 0 feel_c = 0 try: weather = parsed_json['current_observation']['weather'] temp_f = float(parsed_json['current_observation']['temp_f']) temp_c = float(parsed_json['current_observation']['temp_c']) feel_f = float(parsed_json['current_observation']['feelslike_f']) feel_c = float(parsed_json['current_observation']['feelslike_c']) except KeyError as e: weather = 'ERROR' print 'ERROR was registered with KeyError' print e tempString = str(int(temp_f)) + "F " + weather while len(tempString[:16]) < 16: ## ADD SPACES TO FIRST LINE OF WEATHER tempString = tempString + ' ' canFeel = '' if (temp_f - feel_f > 2.0) or (temp_f - feel_f < -2.0): weatherString = tempString[:16] + '\n' + str(int(feel_f)) + 'F feel ' + now.strftime('%H:%M') canFeel = 'It feels like ' + str(int(feel_f)) + ' degrees Fahrenheit. ' + str(int(feel_c)) + ' degrees sell-see-us.' else: weatherString = tempString[:16] + '\nWEATHER ' + now.strftime('%H:%M') f.close() if weatherString != printstring: print weatherString printstring = weatherString lcd.clear() lcd.message(weatherString) print 'printing' lcd.set_color(0,1,1) clothingAdvice = '' if int(temp_f) < 18: clothingAdvice = 'For your safety, wear all cold weather accessories. ' elif int(temp_f) < 32: clothingAdvice = 'Winter coat and hat, likely a scarf too. ' elif int(temp_f) < 46: clothingAdvice = 'Wear a trusy jacket. ' elif int(temp_f) < 60: clothingAdvice = 'Time for a sweater. ' elif int(temp_f) > 74: clothingAdvice = 'Make sure you wear shorts! ' textToSpeak = clothingAdvice + ' It is currently. ' + weather + '. At ' +str(int(temp_f)) + ' degrees Fahrenheit. ' + str(int(temp_c)) + ' degrees sell-see-us. ' + canFeel + ' The time is ' + now.strftime('%H:%M') + '.' if talkingMode == 1 and mode == 14: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") else: print 'suppressed' time.sleep(1.5) mode = 4 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 11), (LCD.UP, 15), (LCD.DOWN, 13), (LCD.RIGHT, 14) ) for button in buttons: if lcd.is_pressed(button[0]): if button[1] != 14: mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MIT SHUTTLE MODE (1) if (mode == 1) or (mode == 11): now = datetime.datetime.now() if ((now.second%30) == 0) or (mode == 11): mitString = "" tempString = "" bus1 = 0 walkBuffer = 8 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 72).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != 'Ct1') and (i.direction.route.title != '1')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == 'Ct1': tempString = str(i.minutes).rjust(2) + 'm BMC Ltd CT1\n' routeToSpeak = "See T One bus to Boston Medical Center, making only Limited Stops." elif i.direction.route.title == '1': tempString = str(i.minutes).rjust(2) + 'm Dudley 1\n' routeToSpeak = "1 bus to Dudley Square." else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") # SOUND TONE elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service \n' + 'to Dudley Square' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 11: os.system("flite -voice kal16 -t 'No services to, Dudley Square, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 11: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 1 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 12), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 13) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA NORTH PREDICTIONS MODE (2) if (mode == 2) or (mode == 12): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 12): mitString = "" tempString = "" bus1 = 0 walkBuffer = 8 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 102).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '1')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '1': routeToSpeak = "1 bus to Harvard Square." tempString = str(i.minutes).rjust(2) + 'm Harvard 1\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No Harvard srvc \n' + 'via Mass Ave ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 12: os.system("flite -voice kal16 -t 'No services to, Harvard Square, via Massachusetts Avenue, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 12: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 2 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 430), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 11) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 3) or (mode == 13): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 13): mitString = "" tempString = "" bus1 = 0 walkBuffer = 3 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 24482).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '64') and (i.direction.route.title != '68')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '64': routeToSpeak = "64 bus to Kendall M-I-T, station." tempString = str(i.minutes).rjust(2) + 'm Kendall 64\n' elif i.direction.route.title == '68': routeToSpeak = "68 bus to Kendall M-I-T, station." tempString = str(i.minutes).rjust(2) + 'm Kendall 68\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service \n' + 'to Kendall/MIT ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 13: os.system("flite -voice kal16 -t 'No services to, Kendall M-I-T station, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 13: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 3 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 11), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 420) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 43) or (mode == 430): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 430): mitString = "" tempString = "" bus1 = 0 walkBuffer = 5 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 1423).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '69')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '69': routeToSpeak = "69 bus to Harvard Square." tempString = str(i.minutes).rjust(2) + 'm Harvard 69\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No Harvard srvc \n' + 'via Cambridge St' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 430: os.system("flite -voice kal16 -t 'No services to, Harvard Square, via Cambridge Street, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 430: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 43 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 450), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 12) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 45) or (mode == 450): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 450): mitString = "" tempString = "" bus1 = 0 walkBuffer = 4 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 2441).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '83') and (i.direction.route.title != '91')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '91': routeToSpeak = "91 bus to Central Square." tempString = str(i.minutes).rjust(2) + 'm Central 91\n' elif i.direction.route.title == '83': routeToSpeak = "83 bus to Central Square." tempString = str(i.minutes).rjust(2) + 'm Central 83\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service to \n' + 'Central Sq ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 450: os.system("flite -voice kal16 -t 'No services to, Central Square, via Prospect Street, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 450: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 45 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 480), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 430) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 48) or (mode == 480): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 480): mitString = "" tempString = "" bus1 = 0 walkBuffer = 5 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 2524).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '85')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '85': routeToSpeak = "85 bus to Spring Hill via Union Square." tempString = str(i.minutes).rjust(2) + 'm Sprg Hill 85\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service to \n' + 'Spring Hill ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 480: os.system("flite -voice kal16 -t 'No services to, Spring Hill, via Union Square, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 480: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 48 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 490), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 450) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 49) or (mode == 490): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 490): mitString = "" tempString = "" bus1 = 0 walkBuffer = 6 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 2514).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '85') and (i.direction.route.title != 'Ct2')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '85': routeToSpeak = "85 bus to Kendall M-I-T, station." tempString = str(i.minutes).rjust(2) + 'm Kendall 85\n' elif i.direction.route.title == 'Ct2': routeToSpeak = "C-T-2 bus to Ruggles, making only Limited Stops." tempString = str(i.minutes).rjust(2) + 'm Rgls Ltd CT2\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service to \n' + 'Ruggles St ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 490: os.system("flite -voice kal16 -t 'No services toward Ruggles Street, station, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 490: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 49 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 520), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 480) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 47) or (mode == 470): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 470): mitString = "" tempString = "" bus1 = 0 walkBuffer = 11 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 1123).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '64')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '64': routeToSpeak = "64 bus to Oak Square." tempString = str(i.minutes).rjust(2) + 'm Oak Sq 64\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service to \n' + 'Oak Sq via 64 ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 470: os.system("flite -voice kal16 -t 'No services toward Oak Square, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 470: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 47 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 460), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 520) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 46) or (mode == 460): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 460): mitString = "" tempString = "" bus1 = 0 walkBuffer = 11 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 1123).predictions: destination = i.direction.title if (i.minutes < walkBuffer) or ((i.direction.route.title != '70') and (i.direction.route.title != '70a') and (i.direction.route.title != '70A')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '70a' or i.direction.route.title == '70A': routeToSpeak = "70 A bus to North Waltham." tempString = str(i.minutes).rjust(2) + 'm N Walthm 70A\n' elif i.direction.route.title == '70': routeToSpeak = "70 bus to to " + destination if destination == 'Cedarwood': tempString = str(i.minutes).rjust(2) + 'm Cedarwood 70\n' elif destination == 'Market Place Dr': tempString = str(i.minutes).rjust(2) + 'm Market Pl 70\n' elif destination == 'Waltham Center': tempString = str(i.minutes).rjust(2) + 'm Wlthm Ctr 70\n' elif destination == 'Watertown Square': tempString = str(i.minutes).rjust(2) + 'm Wtrtwn Sq 70\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service to \n' + 'Watertwn/Waltham' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 460: os.system("flite -voice kal16 -t 'No services toward Waltham, via Watertown, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 460: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 46 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 510), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 470) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 51) or (mode == 510): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 510): mitString = "" tempString = "" bus1 = 0 walkBuffer = 3 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 24489).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '64') and (i.direction.route.title != '68')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '68': routeToSpeak = "68 bus to Harvard Square." tempString = str(i.minutes).rjust(2) + 'm Harvard 68\n' elif i.direction.route.title == '64': routeToSpeak = "64 bus to Oak Square, at Broadway and Norfolk Streets." tempString = str(i.minutes).rjust(2) + 'm Oak Sq 64\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No Harvard srvc \n' + 'via Broadway ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 510: os.system("flite -voice kal16 -t 'No services toward Harvard Square, via Broadway, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 510: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 51 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 440), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 460) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE if (mode == 52) or (mode == 520): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 520): mitString = "" tempString = "" bus1 = 0 walkBuffer = 9 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 72).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '47')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '47': routeToSpeak = "47 bus to Broadway." tempString = str(i.minutes).rjust(2) + 'm Broadway 47\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service to \n' + 'Broadway Sta ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 520: os.system("flite -voice kal16 -t 'No services toward Broadway, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 520: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 52 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 470), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 490) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA PREDICTIONS MODE special for Ryan Fish (walkBuffer < 4, timeToRing == 6) if (mode == 449) or (mode == 4409): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 4409): mitString = "" tempString = "" bus1 = 0 walkBuffer = 4 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 2448).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '83') and (i.direction.route.title != '91')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '83': routeToSpeak = "83 bus to Rindge Avenue." tempString = str(i.minutes).rjust(2) + 'm Rindge Av 83\n' else: continue if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == 6 and hasTalked == False: tts = gtts.gTTS(text="Good morning, Ryan Fish. It's time to leave. Bye.", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("aplay /home/pi/infoMini/two_tone.wav") os.system("omxplayer -o local tempAudioOutput.mp3") hasTalked = True elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No srvc to Rindge\n' + 'Av and Sullivan' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 4409: os.system("flite -voice kal16 -t 'No services toward neither Rindge, Avenue, nor, Sullivan Square, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 4409: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 449 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 420), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 510) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 if (now.hour == 8) and (now.minute >= 42) and (now.weekday() <= 4): mode = 1000 ## MBTA PREDICTIONS MODE if (mode == 44) or (mode == 440): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 440): mitString = "" tempString = "" bus1 = 0 walkBuffer = 4 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 2448).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '83') and (i.direction.route.title != '91')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '83': routeToSpeak = "83 bus to Rindge Avenue, via Porter Square." tempString = str(i.minutes).rjust(2) + 'm Rindge Av 83\n' elif i.direction.route.title == '91': routeToSpeak = "91 bus to Sullivan Square." tempString = str(i.minutes).rjust(2) + 'm Sullivan 91\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No srvc to Rindge\n' + 'Av and Sullivan' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 440: os.system("flite -voice kal16 -t 'No services toward neither Rindge, Avenue, nor, Sullivan Square, are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 440: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 44 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 420), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 510) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 if (now.hour == 8) and (now.minute >= 42) and (now.weekday() <= 4): mode = 1000 ## MBTA PREDICTIONS MODE if (mode == 42) or (mode == 420): now = datetime.datetime.now() if ((now.second%20) == 0) or (mode == 420): mitString = "" tempString = "" bus1 = 0 walkBuffer = 6 textToSpeak = "" routeToSpeak = "" for i in get_predictions_for_stop('mbta', 1406).predictions: if (i.minutes < walkBuffer) or ((i.direction.route.title != '69')): # this means either there is not enough time to walk to # reasonably walk to the bus stop or the relevant bus is # neither Route 1 nor Route Ct1 continue if i.direction.route.title == '69': routeToSpeak = "69 bus to Leechmere Square." tempString = str(i.minutes).rjust(2) + 'm Lechmere 69\n' else: tempString = str(i.minutes).rjust(2) + 'm Unknown dest\n' if len(mitString) < 5: textToSpeak = "The next. " + routeToSpeak + " arrives in," + str(i.minutes) + ", minutes." #print 'case 1: tempString first' #print tempString #print 'now mitString' #print mitString mitString = tempString if i.minutes > walkBuffer + 6: lcd.set_color(0,0,1) # BLUE if (i.minutes > walkBuffer + 3) and (i.minutes <= walkBuffer + 6): lcd.set_color(0,1,0) # GREEN if i.minutes <= walkBuffer + 3: lcd.set_color(1,0,0) # RED if i.minutes == walkBuffer + 3 and (talkingMode == 1 or talkingMode == 2): os.system("aplay /home/pi/infoMini/two_tone.wav") elif (len(mitString) < 25) and (len(mitString) > 10): #print 'case 2: tempString first' #print tempString #print 'now mitString' #print mitString mitString = mitString + tempString if mitString == "": mitString = 'No service to \n' + 'Lechmere Sq ' printstring = mitString lcd.clear() lcd.set_color(1,0,0) # RED lcd.message(mitString) if talkingMode == 1 and mode == 420: os.system("flite -voice kal16 -t 'No services toward Lechmere Square are currently operating.'") elif mitString != printstring: printstring = mitString lcd.clear() lcd.message(mitString) if talkingMode == 1 and mode == 420: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 42 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 13), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 440) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## MBTA RED LINE SOUTH PREDICTIONS MODE if (mode == 400) or (mode == 4000): now = datetime.datetime.now() if ((now.second%30) == 0) or (mode == 400): mitString = "" tempString = "" bus1 = 0 walkBuffer = 8 textToSpeak = "" routeToSpeak = "" r = RedLine( query_type='predictionsbystop', direction='southbound', stop='70069') textToSpeak = r.return_predictions() if talkingMode == 1 and mode == 400: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 4000 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 1), (LCD.UP, 401), (LCD.DOWN, 10), (LCD.RIGHT, 2) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 if (now.hour == 9) and (now.minute >= 50) and (now.weekday() <= 4): mode = 1000 ## MBTA RED LINE SOUTH PREDICTIONS MODE special version for jfabi on mornings if (mode == 4009) or (mode == 40009): now = datetime.datetime.now() if ((now.second%30) == 0) or (mode == 4009): mitString = "" tempString = "" bus1 = 0 walkBuffer = 8 textToSpeak = "" routeToSpeak = "" r = RedLine( query_type='predictionsbystop', direction='southbound', stop='70069') textToSpeak = r.return_predictions() #if talkingMode == 1 and mode == 4009: # tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") # tts.save("tempAudioOutput.mp3") # os.system("omxplayer -o local tempAudioOutput.mp3") mode = 40009 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 1), (LCD.UP, 401), (LCD.DOWN, 10), (LCD.RIGHT, 2) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 if (now.hour == 9) and (now.minute >= 50) and (now.weekday() <= 4): mode = 1000 ## MBTA RED LINE NORTH PREDICTIONS MODE if (mode == 401) or (mode == 4010): now = datetime.datetime.now() if ((now.second%30) == 0) or (mode == 401): mitString = "" tempString = "" bus1 = 0 walkBuffer = 8 textToSpeak = "" routeToSpeak = "" r = RedLine( query_type='predictionsbystop', direction='northbound', stop='70070') textToSpeak = r.return_predictions() if talkingMode == 1 and mode == 401: tts = gtts.gTTS(text=textToSpeak + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") mode = 4010 ## CHECK BUTTONS buttons = ( (LCD.SELECT, 10), (LCD.LEFT, 1), (LCD.UP, 400), (LCD.DOWN, 10), (LCD.RIGHT, 2) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## IMPLEMENT TIMER TO REVERT TO mode = 0 ## DEFAULT TIME AND DATE MODE (0) if (mode == 0) or (mode == 10) or (mode == 1000): now = datetime.datetime.now() if (now.hour == 3): ## Every morning at 03:00, reset the 'hasTalked' flag hasTalked = False if (now.hour == 8) and (now.minute == 15) and (now.weekday() <= 4): if mode == 10: oldMode = 1000 else: oldMode = mode mode = 4409 if (now.hour == 8) and (now.minute == 45) and (now.weekday() <= 4): if mode == 10: oldMode = 1000 else: oldMode = mode mode = 4009 if (now.second == 59) and ((now.minute%10) == 0): print str(now.second) print str(now.minute) if mode == 10: oldMode = 1000 else: oldMode = mode mode = 33 if (((now.second%15) == 0) or (mode == 10)) and (mode < 30): ## GRAB CURRENT STATUS FROM JFABI try: status_list = api.GetUserTimeline(screen_name='jfabi_info', count='1') statuses = [s.text for s in status_list] status = statuses[0] print statuses print status ## EXTRACT COLOUR CODE, IF PRESENT temp_colour_x = colour_x if status[1] == ' ': temp_colour_x = status[0] status_text = status[2:] else: status_text = status except twitter.error.TwitterError: print 'ERROR TwitterError (not printing)' status_text = old_status except twitter.TwitterError: print 'ERROR TwitterError (not printing)' status_text = old_status except ConnectionError as e: print 'ERROR ConnectionError (see below):' print e status_text = old_status except TypeError as e: print 'ERROR TypeError (see below):' print e status_text = old_status except: print 'ERROR generic/unknown (not printing)' status_text = old_status ## TRUNCATE TWEET TO 16 CHAR, IF REQUIRED length = len(status_text) #print length print "check 5 - " + now.strftime('%H:%M:%S') text_to_use = ' ' if (temp_colour_x == 'X' or temp_colour_x == 'Y') and old_status != '': text_to_use = old_status_without_x else: text_to_use = status_text if length > 16: final_status_with_x = status_text[:16] final_status = text_to_use[:16] else: final_status_with_x = status_text final_status = text_to_use ## IF NEED BE, ADD SPACES TO FINAL_STATUS VIA WHILE LOOP while len(final_status) < 16: final_status = ' ' + final_status #print len(final_status) while len(final_status_with_x) < 16: final_status_with_x = ' ' + final_status_with_x #print len(final_status_with_x) ## SET LED COLOUR BASED ON FIRST CHARACTER OF TWEET if temp_colour_x == 'R': lcd.set_color(1,0,0) colour_x = 'R' elif temp_colour_x == 'G': lcd.set_color(0,1,0) colour_x = 'G' elif temp_colour_x == 'B': lcd.set_color(0,0,1) colour_x = 'B' elif temp_colour_x == 'N': lcd.set_color(0,0,0) colour_x = 'N' elif temp_colour_x == 'P': lcd.set_color(1,0,1) colour_x = 'P' elif temp_colour_x == 'T': lcd.set_color(0,1,1) colour_x = 'T' elif temp_colour_x == 'S': lcd.set_color(1,1,0) colour_x = 'S' elif temp_colour_x == 'W': lcd.set_color(1,1,1) colour_x = 'W' elif colour_x == '': lcd.set_color(1,1,1) elif colour_x == 'R': lcd.set_color(1,0,0) elif colour_x == 'G': lcd.set_color(0,1,0) elif colour_x == 'B': lcd.set_color(0,0,1) elif colour_x == 'N': lcd.set_color(0,0,0) elif colour_x == 'P': lcd.set_color(1,0,1) elif colour_x == 'T': lcd.set_color(0,1,1) elif colour_x == 'S': lcd.set_color(1,1,0) elif colour_x == 'W': lcd.set_color(1,1,1) date_display = now.strftime('%a %d') time_display = ' ' + now.strftime('%H:%M') ## DISPLAY TIME/DATE, TITLE, TWEET TO CONSOLE display_text = final_status + '\n' #print display_text #print date_display #print time_display ## CHECK BUTTONS buttons = ( (LCD.SELECT, 100), (LCD.LEFT, 11), (LCD.UP, 15), (LCD.DOWN, 13), (LCD.RIGHT, 14) ) for button in buttons: if lcd.is_pressed(button[0]): mode = button[1] ## FINALISE STRING FOR DISPLAY #print len(display_text) #print display_text if len(display_text) == 17: display_text = display_text + 'jfabi ' spaces = 34 - len(display_text) - 6 for sp in range(1,spaces): display_text = display_text + ' ' if (now.second%10) < 6: display_text = display_text + time_display else: display_text = display_text + date_display if mode == 10 or mode == 1000: mode = 0 lcd.clear() print display_text printstring = display_text lcd.message(display_text) print 'printing ' + now.strftime('%H:%M:%S') if talkingMode == 1 and mode == 10: tts = gtts.gTTS(text=status_text, lang="en-uk") tts.save("tempAudioOutput.mp3") os.system("omxplayer -o local tempAudioOutput.mp3") elif old_status == final_status_with_x: printstring = display_text lcd.message(display_text) # print 'supressed' elif status_text != 'ERROR' and temp_colour_x != 'X' and temp_colour_x != 'Y': # this means we have actually updated tweet, so ring bell lcd.clear() print display_text printstring = display_text lcd.message(display_text) print 'printing ' + now.strftime('%H:%M:%S') if talkingMode == 1: tts = gtts.gTTS(text=status_text + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") # ring bell here os.system("aplay /home/pi/infoMini/two_tone.wav") os.system("aplay /home/pi/infoMini/one_tone.wav") os.system("omxplayer -o local tempAudioOutput.mp3") elif (temp_colour_x == 'X' or temp_colour_x == 'Y'): if talkingMode == 1: tts = gtts.gTTS(text=status_text + " ", lang="en-uk") tts.save("tempAudioOutput.mp3") # ring bell here print 'only talking ' + now.strftime('%H:%M:%S') if temp_colour_x == 'X': os.system("aplay /home/pi/infoMini/two_tone.wav") os.system("aplay /home/pi/infoMini/two_tone.wav") os.system("omxplayer -o local tempAudioOutput.mp3") # if temp_colour_x != 'X': old_status = final_status_with_x old_status_without_x = final_status ## IMPLEMENT TIMER TO REVERT TO mode = 0