Exemple #1
0
def ex(cmd):
    date = datetime.now()

    hour = date.strftime("%H")
    minute = date.strftime("%M")

    tts.speak(replying.get_reply("time").format(hour, minute))
Exemple #2
0
def ex(cmd):
    notes_file_data = {"notes": []}

    with open(settings.NOTES_FILE_PATH, "w", encoding="utf-8") as notes_file:
        json.dump(notes_file_data, notes_file, indent=2, ensure_ascii=False)

    tts.speak(replying.get_reply("note_clear"))
Exemple #3
0
def ex(cmd):
    with open(settings.NOTES_FILE_PATH, "r+", encoding="utf-8") as notes_file:
        notes_file_data = json.load(notes_file)

    new_note = cmd["input"].replace(cmd["text"] + " ", "")

    notes_file_data["notes"].append(new_note)

    with open(settings.NOTES_FILE_PATH, "w", encoding="utf-8") as notes_file:
        json.dump(notes_file_data, notes_file, indent=2, ensure_ascii=False)

    tts.speak(replying.get_reply("note_add").format(new_note))
Exemple #4
0
    def greet(self) -> None:
        log.debug("Greeting...")

        printy(self.fig.renderText("pyVoice"), "nB")
        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.speak(replying.get_reply("greet", system=True, stage=3))
Exemple #5
0
def execute_match(cmd) -> None:
    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.speak(
            replying.get_reply(["matching", "fail"], system=True, module=True))
Exemple #6
0
def ex(cmd):
    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 one")

    date = datetime.now()

    day = date.strftime("%d").lstrip("0")
    month = date.strftime("%B")
    year = date.strftime("%Y")

    tts.speak(replying.get_reply("date").format(day, month, year))
Exemple #7
0
def test_match(cmd_input) -> dict:
    cmd = {"name": None, "text": None, "input": cmd_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 cmd_input.lower():
            tts.speak(
                replying.get_reply(["matching", "ask"],
                                   system=True,
                                   module=True).format(keyword))
            yn_input = stt.listen_for_binary()
            # 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(
                    cmd_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.speak(
                    replying.get_reply(["matching", "added"],
                                       system=True,
                                       module=True))
                cmd = {
                    "name":
                    cmd_title,
                    "text":
                    phrases_file_data[cmd_title][settings.LANGUAGE]["data"][0],
                    "input":
                    cmd_input,
                }
                return cmd
Exemple #8
0
def ex(cmd):
    country_name = settings.COUNTRY.lower()

    api_url = "https://api.covid19api.com/total/country/{0}/status/confirmed".format(
        country_name
    )

    try:
        res = requests.get(api_url).json()[-1]
        total_cases = res["Cases"]

        tts.speak(
            replying.get_reply("covid").format(country_name.capitalize(), total_cases)
        )
    except requests.ConnectionError:
        log.error("An error ocurred while loading the data, try again later...")
    except:
        log.error("An error ocurred, try again later...")
Exemple #9
0
def ex(cmd):
    url = "http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&lang={2}&units=metric".format(
        settings.LOCATION, settings.WEATHER_API_KEY, settings.LANGUAGE_SHORT)

    data = requests.get(url)
    content = json.loads(data.text)

    if "message" in content:
        log.error(content["message"])
        tts.speak("An error ocurred: " + content["message"])
    else:
        temp = content["main"]["temp"]
        temp_max = content["main"]["temp_max"]
        description = content["weather"][0]["description"]

        tts.speak(
            replying.get_reply("weather").format(settings.LOCATION, temp,
                                                 description, temp_max))
Exemple #10
0
def ex(cmd):
    keywords = cmd.replace(settings.KEYWORD + " ",
                           "").lower().replace(" ", "+")
    url = "https://www.google.com/search?q={0}&hl={1}".format(
        keywords, settings.LANGUAGE_SHORT)

    source_code = requests.get(url).text
    soup = BeautifulSoup(source_code, features="html.parser")

    try:
        text_tag = soup.find("div", {"class": "BNeawe iBp4i AP7Wnd"})
        output = text_tag.getText()
    except Exception:
        text_tag = soup.find("div", {
            "class": "xpc"
        }).find("div", {"class": "BNeawe s3v9rd AP7Wnd"})
        output = text_tag.getText()

    tts.speak(output)
Exemple #11
0
def ex(cmd):
    with open(settings.NOTES_FILE_PATH, "r+", encoding="utf-8") as notes_file:
        notes_file_data = json.load(notes_file)

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

    if len(notes_file_data["notes"]) == 0:
        tts.speak(replying.get_reply("notes_read", stage=1))
    else:
        for note in notes_file_data["notes"]:
            tts.speak(note)
            time.sleep(0.5)
def ex(cmd) -> None:
    if utils.check_if_registered() is False:
        # tries to register the install
        res = api.register_install()

        # check if an error ocurred
        if "detail" in res:
            tts.speak(replying.get_reply("register_install", stage=1))
        else:
            utils.switch_registered_field()
            tts.speak(replying.get_reply("register_install", stage=0))
    else:
        tts.speak(replying.get_reply("register_install", stage=2))
Exemple #13
0
def ex(cmd):
    tts.speak(
        "I am pyVoice, a voice assistant created by Afonso Santos. You can call me {0}".format(
            settings.KEYWORD
        )
    )
Exemple #14
0
def ex(cmd):
    tts.speak(replying.get_reply("help"))