def alarm(): light.on() db = get_db() # write state of lamp to database db.execute( "update lamp set brightness = ?, red = ?, green = ?, blue = ? where id = 0;", (brightness, red, green, blue)) db.commit() # light.utilities.update_grid(1) return redirect(url_for('home'))
def execute_alarm(): logger.info('Executing alarm...') username = goodclock_spotify.get_current_username() playlist_uri = goodclock_spotify.get_or_create_goodclock_playlist(username) track_url = goodclock_spotify.get_random_playlist_track_preview_url( username, playlist_uri) if track_url: path = save_audio_file_for_track_data(track_url) else: path = settings.DEFAULT_TRACK_PATH light.on() run_alarm_with_audio_file(path) return True
def index(): """Main view, set and display light current light status""" db = get_db() if request.method == "POST": try: brightness = int(request.form["brightness"]) red = int(request.form["red"]) green = int(request.form["green"]) blue = int(request.form["blue"]) except ValueError: brightness = -1 red = -1 green = -1 blue = -1 if brightness not in range(101): error = "Brightness must be a percentage value (0 - 100)" elif (red not in range(256) or green not in range(256) or blue not in range(256)): error = "rgb values must be in the range 0 - 255" else: error = None if error is None: db.execute( """update light set brightness = ?, red = ?, green = ?, blue = ?""", (brightness, red, green, blue)) db.commit() # call function to turn on light # or implement light code here? light.on() return redirect(url_for("lamp.index")) flash(error) # get lamp state from database state = db.execute("select * from light").fetchone() return render_template("lamp/index.html", brightness=state["brightness"], red=state["red"], green=state["green"], blue=state["blue"])
def recognize(self): aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY) # 识别本地文件 res=aipSpeech.asr(self.get_file_content(WAVE_OUTPUT_FILENAME), 'wav', 16000, { 'lan': 'zh', }) print res print dircmd for word in res['result']: print word if word[:-1] in dircmd: iscmd=True print "开始打开电视请稍等" if word[:-1] == dircmd[1]: pass elif word[:-1] == dircmd[2]: light.on() elif word[:-1] == dircmd[3]: light.off()
def handle_request(client_socket): request = json.loads(client_socket.recv(1024)) logging.debug("Reveived: %s", request) client_socket.send("ACK!\r\n") # send back a packet client_socket.close() text = request['message']['text'].lower() sender_id = request['sender']['id'].encode('utf8') if u'pic' in text: camera.response_picture(sender_id) elif u'pm' in text: response.response_text(sender_id, pm2_5.PM_DB.discription()) elif u'temp' in text or u'tmp' in text: thermometer.response_temperature(sender_id) elif u'left' in text: servomotor.turn_left() elif u'right' in text: servomotor.turn_right() elif u'light on' in text: light.on() elif u'light off' in text: light.off() else: response.response_text(sender_id, "Try: picture, PM2.5, temperature.")
def on(): light.on() # light.utilities.update_grid(1) return redirect(url_for('home'))