コード例 #1
0
    def action_play(self, query):
        communicator = query.get_communicator()
        text = query.get_text()

        try:
            self.action_continue_playback(query)
            return
        except ImpossibleActionError:
            pass

        if self.main_module.current_song() is None:
            self.main_module.play_saved()
            communicator.say("Okay, playing your last added songs.")
            return

        # fetch all playlist macros from config file and search for matches in the query
        playlists = Config.get_instance().get_section_content('playlists')
        for playlist in playlists:
            if playlist[0].lower() in text.lower():
                self.main_module.play_playlist(playlist[1])
                communicator.say("Okay, I'll now play the playlist" +
                                 playlist[0] + ".")
                return

        self.main_module.play()
        communicator.say("Okay")
        return
コード例 #2
0
 def answer(self, communicator, message):
     """let the assistant answer to the given message
         @param communicator the communicator object used for communication
         @param message string, the assistant should answer to"""
     language = Config.get_instance().get("general", "language")
     query = Query(message.lower(), communicator, language)
     modules = mManager.get_instance().get_modules()
     if not modules:
         communicator.say(self.strings["NO_MODULES"])
         return
     for module in modules:
         """traverse modules and match their regex keys"""
         module = module.get_submodule(query.get_language())
         if module is not None:
             for key_regex, method in module.get_key_regexes().items():
                 if re.match(key_regex, message):
                     try:
                         method(query)
                     except ImpossibleActionError as e:
                         communicator.say(self.strings["KNOWN_ERROR"] +
                                          str(e))
                     except ModuleError as e:
                         communicator.say(self.strings["UNKNOWN_ERROR"])
                         self.logger.error(str(e))
                     except Exception as e:
                         communicator.say(self.strings["UNKNOWN_ERROR"])
                         self.logger.error(str(e))
                     return
     communicator.say(self.strings["NOT_PROCESSABLE"])
コード例 #3
0
    def configure(self):
        config = Config.get_instance()
        client_id = config.get('reddit', 'client_id')
        client_secret = config.get('reddit', 'client_secret')
        user_agent = config.get('reddit', 'user_agent')

        self.reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
コード例 #4
0
    def action_play(self, query):
        communicator = query.get_communicator()
        text = query.get_text()

        try:
            self.action_continue_playback(query)
            return
        except ImpossibleActionError:
            pass

        if self.main_module.current_song() is None:
            communicator.say("Okay, ich spiele jetzt deine zuletzt hinzugefügten Lieder ab")
            self.main_module.play_saved()
            return

        # fetch all playlist macros from config file and search for matches in the query
        playlists = Config.get_instance().get_section_content('playlists')
        for playlist in playlists:
            uri = playlist[1]
            playlist_name = playlist[0]
            if playlist_name.lower() in text.lower():
                self.main_module.play_playlist(uri)
                communicator.say("Ok, die Playlist " + playlist_name + " wird abgespielt")
                return

        communicator.say("Okay")
        self.main_module.play()
        return
コード例 #5
0
 def __init__(self):
     config = Config.get_instance()
     self.address = config.get('mpd', 'address')
     self.port = config.get('mpd', 'port')
     self.client = MPDClient()
     self.client.connect(self.address, self.port)
     self.client.setvol(MpdController.VOLUME)
     self.client.disconnect()
コード例 #6
0
def main():
    """starts Kaspa with desired modules and communicators"""

    # Initialize config directory
    config_dir_path = str(Path.home()) + "/.config/Kaspa/"
    if not os.path.exists(config_dir_path):
        os.makedirs(config_dir_path)
        print("Created Folder" + config_dir_path)

    # Initialize Logger
    logger = logging.getLogger("Kaspa")
    handler = logging.FileHandler(config_dir_path + '/Kaspa.log')
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)

    # add modules
    logger.info("Loading Modules...")
    init_modules()

    # Initialize Config
    Config.set_instance(config_dir_path)
    Config.get_instance().load_modules()

    # Initialize signal handling for Sigint
    signal.signal(signal.SIGINT, sigint_handler)

    # Start mopidy server
    devnull = open(os.devnull, 'w')
    logger.info("Starting mopidy server...")
    subprocess.call("killall mopidy",
                    shell=True,
                    stderr=devnull,
                    stdout=devnull,
                    stdin=devnull)
    subprocess.call("mopidy -q &",
                    shell=True,
                    stderr=devnull,
                    stdout=devnull,
                    stdin=devnull)
    logger.info("Mopidy server started")

    # start communicators
    logger.info("Starting Communicators...")
    start_communicators()
コード例 #7
0
def get_strings(class_name):
    config = Config.get_instance()
    language = config.get("general", "language")
    path = glob.glob(BASE_PATH + language + "/**/" + class_name + "*",
                     recursive=True)
    file = open(path[0], "r")
    strings = json.load(file)
    file.close()
    return strings
コード例 #8
0
 def configure(self):
     try:
         bridge_ip = Config.get_instance().get("hue", "bridge_ip")
         self.bridge = Bridge(bridge_ip)
     except phue.PhueRegistrationException:
         # TODO figure out how to localize error message here
         raise ImpossibleActionError(
             "You have to press the button on your bridge first!")
     except Exception as e:
         raise ModuleError(self.module_name, str(e))
コード例 #9
0
 def action(self, query):
     query_text = query.get_text()
     communicator = query.get_communicator()
     config = Config.get_instance()
     home = config.get('locations', 'home')
     locations = config.get_section_content('locations')
     for location in locations:
         if location[0] in query_text:
             communicator.say(self.get_simple_transit(home, location[1]))
             return
     location = communicator.ask(
         "This location is not in your saved locations. "
         "\n Can you please repeat where you want to go?")
     communicator.say(self.get_simple_transit(home, location))
コード例 #10
0
ファイル: spotify.py プロジェクト: karim-awad/kaspa
 def __init__(self):
     config = Config.get_instance()
     self.client_id = config.get("spotify", "client_id")
     self.client_secret = config.get("spotify", "client_secret")
     self.username = config.get("spotify", "username")
     os.environ["SPOTIPY_CLIENT_ID"] = "self.client_id"
     os.environ["SPOTIPY_CLIENT_SECRET"] = "self.client_secret"
     os.environ["SPOTIPY_REDIRECT_URI"] = "http://localhost/'"
     self.token = util.prompt_for_user_token(
         self.username,
         self.scope,
         client_id=self.client_id,
         client_secret=self.client_secret,
         redirect_uri='http://localhost/')
     self.spotipy = spotipy.Spotify(auth=self.token)
コード例 #11
0
 def action(self, query):
     query_text = query.get_text()
     communicator = query.get_communicator()
     config = Config.get_instance()
     home = config.get('locations', 'home')
     # search for saved location in config
     locations = config.get_section_content('locations')
     for location in locations:
         if location[0] in query_text:
             # location is in shortcuts => show simple transit
             communicator.say(self.get_simple_transit(home, location[1]))
             return
     location = communicator.ask(
         "Der Ort befindet sich nicht unter deinen gespeicherten Orten. "
         "\n Kannst du ihn bitte nocheinmal wiederholen?")
     # new location => show full transit
     communicator.say(self.get_transit(home, location))
コード例 #12
0
ファイル: ifttt.py プロジェクト: karim-awad/kaspa
def send_event(event, value1=None, value2=None, value3=None):
    """Send an event to the IFTTT maker channel
    Parameters:
    -----------
    api_key : string
        Your IFTTT API key
    event : string
        The name of the IFTTT event to trigger
    value1 :
        Optional: Extra data sent with the event (default: None)
    value2 :
        Optional: Extra data sent with the event (default: None)
    value3 :
        Optional: Extra data sent with the event (default: None)
    """
    api_key = Config.get_instance().get("ifttt", "api_key")
    url = 'https://maker.ifttt.com/trigger/{e}/with/key/{k}/'.format(e=event,
                                                                     k=api_key)
    payload = {'value1': value1, 'value2': value2, 'value3': value3}
    return requests.post(url, data=payload)
コード例 #13
0
 def __init__(self):
     super().__init__()
     self.language = Config.get_instance().get("general", "language")
コード例 #14
0
 def __init__(self):
     super().__init__()
     self.api_key = Config.get_instance().get('telegram', 'api_key')
     self.chat_id = Config.get_instance().get('telegram', 'chat_id')
コード例 #15
0
 def configure(self):
     self.api_key = Config.get_instance().get('wolfram alpha', 'api_key')
コード例 #16
0
 def __init__(self):
     config = Config.get_instance()
     self.mac = config.get("pc", "mac")
     self.hostname = config.get("pc", "hostname")
     self.user = config.get("pc", "user")
コード例 #17
0
 def __init__(self, chat_id, bot, update):
     super().__init__(class_name="TelegramCommunicator")
     self.api_key = Config.get_instance().get('telegram', 'api_key')
     self.chat_id = chat_id
     self.bot = bot
     self.update = update
コード例 #18
0
 def stt(self):
     r = sr.Recognizer()
     with sr.AudioFile(self.AUDIO_FILE) as source:
         audio = r.record(source)  # read the entire audio file
         language = Config.get_instance().get("general", "language")
         return r.recognize_google(audio, language=language)
コード例 #19
0
 def __init__(self):
     self.api_key = Config.get_instance().get("bing", "api_key")
コード例 #20
0
 def configure(self):
     api_key = Config.get_instance().get("google maps", "api_key")
     self.google_maps = googlemaps.Client(key=api_key)
コード例 #21
0
 def configure(self):
     config = Config.get_instance()
     self.api_key = config.get('weather', 'api_key')
     self.lat = config.get('weather', 'latitude')
     self.lng = config.get('weather', 'longitude')