def __init__(self, callback, language="pl-PL", api_option=ApiOption.GOOGLE):
        super().__init__()
        self.callback_command_detected = callback
        self.api_option = api_option
        self.language = language
        self.listen_thread = None
        self.phrase_time_limit = 3

        try:
            self.recognizer = Recognizer()
            self.microphone = Microphone()
            """
                adjust the recognizer sensitivity to ambient noise and record audio
                from the microphone
            """
            with self.microphone as source:
                self.recognizer.adjust_for_ambient_noise(source)

        except OSError as ose_err:
            Logger.critical("OSError: {0}".format(ose_err))
            self.api_runs = False
            self.api_info = GLO_MSG['MICROPHONE_FAILURE']
            return
        except Exception as err:
            Logger.critical("Exception: {0}".format(err))
            self.api_runs = False
            self.api_info = GLO_MSG['MICROPHONE_FAILURE']
            return
        Logger.debug("Initialization of CommandsRecognition class")
        self.api_info = GLO_MSG['MICROPHONE_INITIALIZED']
示例#2
0
 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)
示例#3
0
    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)
示例#4
0
 def get_location():
     try:
         location_req_url = "http://ip-api.com/json/{0}".format(Network.get_ip())
         response = requests.get(location_req_url)
         location_json = json.loads(response.text)
         Logger.debug("request: " + str(location_req_url) + " response: " + str(response)
                      + " json: " + str(location_json))
         return location_json
     except Exception as err:
         Logger.critical("Exception: {0}".format(err))
         return None
示例#5
0
 def get_ip():
     try:
         ip_reg_url = "http://jsonip.com/"
         response = requests.get(ip_reg_url)
         ip_json = json.loads(response.text)
         Logger.debug("request: " + str(ip_reg_url) + " response: " + str(response)
                      + " json: " + str(ip_json))
         return ip_json['ip']
     except Exception as err:
         Logger.critical("Exception: {0}".format(err))
         return None
示例#6
0
 def _camera_connection(self):
     Logger.debug("Find camera connection")
     try:
         self.camera = cv2.VideoCapture(0)
         if not self.camera.isOpened():
             raise NameError
     except cv2.error as exception:
         Logger.critical(
             "OpenCV camera hardware problem: {0}".format(exception))
         self.api_info = GLO_MSG['API_CAMERA_CONNECTION_FAILURE']
         self.api_runs = self.Disabled
         return
     except Exception as exception:
         Logger.critical(
             "Camera hardware is not connected: {0}".format(exception))
         self.api_info = GLO_MSG['API_CAMERA_CONNECTION_FAILURE']
         self.api_runs = self.Disabled
         return
     self.api_info = GLO_MSG['API_WINDOW_INITIALIZED']
     self.api_runs = self.Enabled
     return
示例#7
0
 def enabled():
     global network_status
     try:
         socket.setdefaulttimeout(3)
         socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("8.8.8.8", 53))
         network_status = GLO_MSG['NETWORK_CONNECTION_SUCCESS']
         Logger.debug("Internet connection enabled")
         return True
     except socket.error as socket_error:
         network_status = GLO_MSG['NETWORK_CONNECTION_FAILURE']
         Logger.critical("Internet connection disabled socket.error : {0}".format(socket_error))
         return False
     except OSError as ose_error:
         network_status = GLO_MSG['NETWORK_CONNECTION_FAILURE']
         Logger.critical("Internet connection disabled OSError : {0}".format(ose_error))
         return False
     except Exception as err:
         network_status = GLO_MSG['NETWORK_CONNECTION_FAILURE']
         Logger.critical("Internet connection disabled exception : {0}".format(err))
         return False