def say(self, text): try: Logger.info("Speaker say : {0}".format(text)) self.engine_speak.say(text) self.engine_speak.runAndWait() except Exception as err: Logger.error("Speaker error : {0}".format(err))
def validate_command(self, command): if command.lower() in GLO_CMD.values(): detected_command_id = GET_COMMAND(command.lower()) Logger.info("GLO_CMD command available -> {0}".format(command.lower())) self.callback_command_detected(detected_command_id) else: Logger.info("Detected command: {0}".format(command.lower()))
def run(self): Logger.info("User_Interface thread runs") self.init_window() self.init_camera() self.run_authorization() while not self.close_thread: self.run_api_window() self.run_messages_handler() Logger.info("User_Interface thread ends")
def get_headlines(self): try: self.news_list = feedparser.parse(self.news_url) Logger.info("Get number of news: {0} from: {1}".format( len(self.news_list), self.news_url)) except Exception as err: Logger.critical("News exception: {0}".format(err)) # updates every 5 minutes self.after(5 * 60 * 1000, self.get_headlines)
def get_weather(self): location_info = Network.get_location() if self.location_info != location_info: self.location_info = location_info latitude = self.location_info['lat'] longitude = self.location_info['lon'] location = "{1} {2}, {0}".format(self.location_info['country'], self.location_info['city'], self.location_info['zip']) try: weather_req_url = "https://api.darksky.net/forecast/{0}/{1},{2}?lang={3}&units={4}".format( self.weather_api_token, latitude, longitude, self.weather_lang, self.weather_unit) response = requests.get(weather_req_url) weather_info = json.loads(response.text) Logger.debug("request: " + str(weather_req_url) + " response: " + str(response) + " json: " + str(weather_info)) except Exception as err: Logger.critical("Exception: {0}".format(err)) return None if self.weather_info != weather_info: self.weather_info = weather_info degree_sign = u'\N{DEGREE SIGN}' temperature = "{0}{1}".format( str(int(self.weather_info['currently']['temperature'])), degree_sign) currently = self.weather_info['currently']['summary'] forecast = self.weather_info["hourly"]["summary"] icon_id = self.weather_info['currently']['icon'] self.weather_icon = None if icon_id in icons: self.weather_icon = icons[icon_id] if self.weather_icon is not None: image = Image.open(self.weather_icon) image = image.resize((100, 100), Image.ANTIALIAS) image = image.convert('RGB') photo = ImageTk.PhotoImage(image) self.icon_label.config(image=photo) self.icon_label.image = photo else: self.icon_label.config(image='') self.currently_label.config(text=currently) self.forecast_label.config(text=forecast) self.temperature_label.config(text=temperature) self.location_label.config(text=location) Logger.info("get_weather") # updates every hour self.after(60 * 60 * 1000, self.get_weather)
def wait_for_ui_initialization(self): Logger.info("Waiting for initialization network and window") def ui_initialized(): return self.window_enabled and self.network_enabled while not (ui_initialized() or self.close_thread): self.run_messages_handler() if ui_initialized(): self.init_command_recognition()
def run(self): Logger.info("User_Command thread runs") self.wait_for_ui_initialization() while not self.close_thread: self.run_messages_handler() Logger.info("User_Command thread ends")
def authorization_callback(self, name): self.authorized_user_name = name self.authorization_complete = True Logger.info("User authorized as: {0}".format(self.authorized_user_name))
""" def init_program_threads(): message_queue = Queue() message_locker = Lock() message_handler = MessagesHandler(messages_queue=message_queue, messages_locker=message_locker) main_ui_thread = UiThread(messages_handler=message_handler) main_ui_thread.start() main_uc_thread = UcThread(messages_handler=message_handler) main_uc_thread.start() message_queue.join() Logger.debug('Threads starts successfully') """ Main function calls by program """ def main(): init_properties() init_program_threads() if __name__ == "__main__": main() Logger.info(__name__ + " ends")