def game_loop(): global current_tick global current_datetime current_datetime = datetime.now() while (current_tick <= datastore.conf("MAX_TICKS")): server.send_message( "datetime", {"datetime": current_datetime.strftime("%Y-%m-%d")}, broadcast=True) user = datastore.find_user_by_username("admin") server.send_message(str(user.id), {"hello": "there"}) time.sleep(datastore.conf("TICK_TIME")) current_tick = current_tick + 1 current_datetime = current_datetime + timedelta(days=1)
def publish(self, _dict): ''' jsonにパースできないのはここで消す(仕様) ''' delete_list = [] for key in _dict: key_type = (type)(_dict[key]) if key_type != str and key_type != bool: delete_list.append(key) # 削除 for i in delete_list: _dict.pop(i) print(self.thread_name, key) print(self.thread_name, " publish : ", _dict, self.thread_name) if IS_ROS_ACTIVE: # 音声認識した結果をROSに送る # voice_pub.publish(_dict) # ここで投げる server.send_message(_dict["word"])
def processing(): data = json.loads(request.data) print(data) if 'type' not in data.keys(): return 'not vk' if data['secret'] != secret_token: return 'not vk' if data['type'] == 'confirmation': return confirmation_token elif data['type'] == 'message_new': peer_id = data['object']['peer_id'] output = server.process(data) if type(output) == type('123'): server.send_message(peer_id, output) elif type(output) == type([1, 2]): for message in output: server.send_message(peer_id, message) return 'ok'
def speak(text: str): server.send_message("TTS_SPEAK", {'text': text})
def update_held_buttons_nowait(to_hold=(), to_release=()): server.send_message("UPDATE_HELD_BUTTONS", { "toHold": to_hold, "toRelease": to_release })
def show_hud_message(msg: str, msg_type: int): server.send_message("SHOW_HUD_MESSAGE", { "message": msg, "msgType": msg_type })
file =open("/tmp/gps_data") SAVE_SYS_LOG = TRUE import syslog syslog.openlog('wifibox-gps',syslog.LOG_PID) def save_syslog(msg) if SAVE_SYSLOG: syslog.syslog(msg) log_info =file.readline() while log_info: #print log_info, log_file =file.readline() if log_info: try: send_message('gps', log_info) save_syslog('send gps-heartbeat') except: print 'append log for gps heartbeat failed\n' save_syslog('send gps-heartbeat failed...') else: try: send_message('gps', {'gps': 'get gps info failed'}) save_syslog('send get gps info failed') except: print 'append log for gps exception failed\n' save_syslog('send gps exception failed') syslog.closelog() file.close()
def listen_print_loop(responses): """Iterates through server responses and prints them. The responses passed is a generator that will block until a response is provided by the server. Each response may contain multiple results, and each result may contain multiple alternatives; for details, see https://goo.gl/tjCPAU. Here we print only the transcription for the top alternative of the top result. In this case, responses are provided for interim results as well. If the response is an interim one, print a line feed at the end of it, to allow the next result to overwrite it, until the response is a final one. For the final one, print a newline to preserve the finalized transcription. """ num_chars_printed = 0 print(datetime.now()) print(datetime.now() + timedelta(minutes=1)) date_limit = datetime.now() + timedelta(minutes=1) try: for response in responses: if not response.results: continue # The `results` list is consecutive. For streaming, we only care about # the first result being considered, since once it's `is_final`, it # moves on to considering the next utterance. result = response.results[0] if not result.alternatives: continue # Display the transcription of the top alternative. transcript = result.alternatives[0].transcript # Display interim results, but with a carriage return at the end of the # line, so subsequent lines will overwrite them. # # If the previous result was longer than this one, we need to print # some extra spaces to overwrite the previous result overwrite_chars = ' ' * (num_chars_printed - len(transcript)) if not result.is_final: sys.stdout.write('\r' + transcript + overwrite_chars) sys.stdout.flush() num_chars_printed = len(transcript) else: print("****** finish ******") print(transcript + overwrite_chars) # 音声認識した結果をROSに送る server.send_message(transcript) # 一回認識するごとに音声認識をリセットする break num_chars_printed = 0 #except ServiceUnavailable as google_err: # print(google_err.headers) # Dump the headers to see # print(google_err.read()) # You can even read this error object just like a normal response file #except not KeyboardInterrupt: #except KeyboardInterrupt: # break # import sys # sys.exit() #except not KeyboardInterrupt: # ''' <Ctrl-c>押された時以外の例外が起きても処理は続行する ''' # import traceback # traceback.print_exc() # pass except: pass