Example #1
0
def ex(cmd):
    tts.say(replying.get_reply("news"))

    # check if language is German
    if settings.LANGUAGE == "en":
        url = "https://indianexpress.com/"
    # else use English
    else:
        url = "https://news.google.com/?hl=en-US&gl=US&ceid=US:en"

    # get the source code from the url
    source_code = requests.get(url).text
    # create a bs4 object
    soup = BeautifulSoup(source_code, features="html.parser")

    # the news dict
    news = []

    class_name = "ipQwMb ekueJc RD0gLb"
    # find every item with thegiven class name
    tags = soup.find_all("h3", {"class": class_name})

    tts.say(replying.get_reply("news", stage=1))

    ticks = 0
    # read every top title
    for tag in tags:
        ticks += 1
        title = tag.getText()
        tts.say(title)
        if ticks >= settings.MAX_NEWS_TICKS:
            break
Example #2
0
def listen_for_yn():
    # get yes and no replies
    yes = replying.get_reply(["stt", "yn_y"], system=True, module=True)
    no = replying.get_reply(["stt", "yn_n"], system=True, module=True)
    log.info("Waiting for {0} or {1}".format(yes, no))
    while True:
        audio = listen()
        input = recognize(audio)
        if input:
            if yes in input.lower():
                log.debug("'{}' detected".format(yes))
                return True
            elif no in input.lower():
                log.debug("'{}' detected".format(no))
                return False
            else:
                log.debug("Not detected in '{}'".format(input))
def ex(cmd):
    # save the command
    # read the file
    with open("data/files/json/notes.json", "r+",
              encoding="utf-8") as notes_file:
        notes_file_data = json.load(notes_file)

    tts.say(replying.get_reply("note_read"))

    if len(notes_file_data["notes"]) == 0:
        tts.say(replying.get_reply("note_read", stage=1))

    else:
        # read every note
        for note in notes_file_data["notes"]:
            tts.say(note)
            time.sleep(0.5)
Example #4
0
def test_match(input):
    cmd = {"name": None, "text": None, "input": input}
    # get phrases file data as json
    with open(settings.PHRASES_FILE_PATH, encoding="utf-8") as phrases_file:
        phrases_file_data = json.load(phrases_file)
    # scan phrases file for match
    # for every command title
    for cmd_title in phrases_file_data:
        keyword = phrases_file_data[cmd_title][settings.LANGUAGE]["keyword"]
        # check if keyword in input
        if keyword in input.lower():
            tts.say(
                replying.get_reply(["matching", "ask"],
                                   system=True,
                                   module=True).format(keyword))
            yn_input = stt.listen_for_yn()
            # if 'yes'
            if yn_input:
                # read the phrases file
                with open(settings.PHRASES_FILE_PATH, "r+",
                          encoding="utf-8") as phrases_file:
                    phrases_file_data = json.load(phrases_file)
                # add the new phrase to the command list
                phrases_file_data[cmd_title][settings.LANGUAGE]["data"].append(
                    input.lower())
                # write the list to the file
                with open(settings.PHRASES_FILE_PATH, "r+",
                          encoding="utf-8") as phrases_file:
                    json.dump(phrases_file_data,
                              phrases_file,
                              indent=2,
                              ensure_ascii=False)
                tts.say(
                    replying.get_reply(["matching", "added"],
                                       system=True,
                                       module=True))
                cmd = {
                    "name":
                    cmd_title,
                    "text":
                    phrases_file_data[cmd_title][settings.LANGUAGE]["data"][0],
                    "input":
                    input
                }
                return cmd
def ex(cmd):
    notes_file_data = {"notes": []}

    # clear file
    with open("assistant\data\files\json\notes.json", "w",
              encoding="utf-8") as notes_file:
        json.dump(notes_file_data, notes_file, indent=2, ensure_ascii=False)

    tts.say(replying.get_reply("note_clear"))
Example #6
0
    def greet(self):
        log.debug("Greeting...")
        print(".........................")
        print(" ")
        print(colored_ascii, end=" ")
        print(" ")
        print(colored_ascii_1, end=" ")
        print(" ")
        print(".........................")
        print("Basic usage:")
        print(
            replying.get_reply("greet", system=True).format(settings.KEYWORD))
        print(
            replying.get_reply("greet", system=True,
                               stage=1).format(settings.KEYWORD))
        print(
            replying.get_reply("greet", system=True,
                               stage=2).format(settings.KEYWORD))

        tts.say(replying.get_reply("greet", system=True, stage=3))
Example #7
0
    def greet(self):
        log.debug("Greeting...")

        print("")
        print(r"         __       __              ")
        print(r"        /\ \__   /\ \__           ")
        print(r"  ___   \ \ ,_\  \ \ ,_\    ___   ")
        print(r" / __`\  \ \ \/   \ \ \/   / __`\ ")
        print(r"/\ \ \ \  \ \ \_   \ \ \_ /\ \ \ \ ")
        print(r"\ \____/   \ \__\   \ \__\\ \____/")
        print(r" \/___/     \/__/    \/__/ \/___/ ")
        print("")
        print("Basic usage:")
        print(
            replying.get_reply("greet", system=True).format(settings.KEYWORD))
        print(
            replying.get_reply("greet", system=True,
                               stage=1).format(settings.KEYWORD))
        print(
            replying.get_reply("greet", system=True,
                               stage=2).format(settings.KEYWORD))

        tts.say(replying.get_reply("greet", system=True, stage=3))
Example #8
0
def execute_match(cmd):
    log.debug("Executing...")
    #
    try:
        # check if command exists as python script
        if commands.__contains__(cmd["name"]):
            log.debug("Replying...")
            commands.get(cmd["name"]).ex(cmd)
        elif cmd["name"] == "google":
            log.debug("Already executed...")
        else:
            log.error("Couldn't match command script")
    # type error: no command found
    except TypeError:
        tts.say(
            replying.get_reply(["matching", "fail"], system=True, module=True))
Example #9
0
def ex(cmd):
    # set locale to get the right month names
    locale.setlocale(locale.LC_TIME, settings.LANGUAGE.replace("-", "_"))

    # get the date
    date = datetime.now()

    # get the day (and remove leading zero)
    day = date.strftime("%d").lstrip("0")

    # get the month name
    month = date.strftime("%B")

    # get the year
    year = date.strftime("%Y")

    tts.say(replying.get_reply("date").format(day, month, year))
Example #10
0
def ex(cmd):
    # save the command
    # read the file
    with open("data/files/json/notes.json", "r+", encoding="utf-8") as notes_file:
        notes_file_data = json.load(notes_file)

    # get the new note
    # new_note = cmd["input"].replace(settings.KEYWORD + " ", "")
    new_note = cmd["input"].replace(cmd["text"] + " ", "")

    # add note to notes
    notes_file_data["notes"].append(new_note)

    # write the list to the file
    with open("data/files/json/notes.json", "w", encoding="utf-8") as notes_file:
        json.dump(notes_file_data, notes_file, indent=2, ensure_ascii=False)

    tts.say(replying.get_reply("note_add").format(new_note))
def ex(cmd):
    # weather request url
    url = "http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&appid={1}&lang={2}&units=metric&cnt=1".format(settings.LOCATION, settings.WEATHER_API_KEY, settings.LANGUAGE_SHORT)

    # get the source code from the url
    data = requests.get(url)
    # convert json
    content = json.loads(data.text)

    # get data
    try:
        # test if there's an error message
        log.error(content["message"])
    except:
        temp = content["main"]["temp"]
        temp_max = content["main"]["temp_max"]
        desc = content["weather"][0]["description"]
        
        tts.say(replying.get_reply("weather").format(settings.LOCATION, temp, desc, temp_max))
Example #12
0
def ex(cmd):
    # set locale to get the right month names
    try:
        locale.setlocale(locale.LC_TIME, settings.LANGUAGE.replace("-", "_"))
    except locale.Error:
        try:
            locale.setlocale(locale.LC_TIME,
                             settings.LANGUAGE.replace("-", "_") + ".utf-8")
        except locale.Error:
            print("Your locale was not found, using default locale")

    # get the date
    date = datetime.now()

    # get the day (and remove leading zero)
    day = date.strftime("%d").lstrip("0")

    # get the month name
    month = date.strftime("%B")

    # get the year
    year = date.strftime("%Y")

    tts.say(replying.get_reply("date").format(day, month, year))