Beispiel #1
0
 def vc_rate_inp():
     try:
         as_vc_rate = int(
             input("Enter the assistant voice rate (Words per minute): ")
         )  #DEF=200 wpm
         return as_vc_rate
     except:
         voice_io.show("Invalid Input! Please Try Again!")
         return vc_rate_inp()
Beispiel #2
0
def tm_hello():
    time = datetime.datetime.now().strftime("%H")
    time = int(time)
    if time < 12:
        tm = "Morning"  ##$$
    elif 12 <= time < 18:
        tm = "Afternoon"
    else:
        tm = "Evening"
    voice_io.show("Good", tm, gnd())
Beispiel #3
0
def setNewUser():
    usr_info_dic = {}
    clear.clear()
    voice_io.show("What shall I call you Master? ")
    nm = bytes(
        invoice.inpt(), encoding="utf-8"
    )  #Name of the user i.e the name by which the assistant will call him/her
    voice_io.show(
        "\nAnd you are, Master or Miss, master? ")  #Gender of the user
    gnd = invoice.inpt()
    asst_pswd = bytes(getpass.getpass(
        voice_io.show("\nWhat should be your password for accessing me?",
                      show_output=False) + "\nPassword: "******"utf-8")
    salt = b'$2b$12$3hbla5Xs2Ekx9SGVYfWQuO'
    hashed_pswd = bcrypt.hashpw(asst_pswd, salt)
    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=salt,
        iterations=100000,
    )
    global key
    key = base64.urlsafe_b64encode(kdf.derive(hashed_pswd))
    #with open(get_dirs.FILE_ENCRYPT_KEY,'wb+') as f:
    #    f.write(key)
    voice_io.show(
        "\nAnd now what would be your 'gmail' address? Note: Right now I support gmail (google) accounts only, so please make one if you don't have one already, to continue! "
    )
    eml = bytes(invoice.inpt(processed=False), encoding="utf-8")
    print(
        "\nLastly I need you to authenticate this with Daddy Google for me, you can skip this now but know that I will be needing this to perform Email Operations! Press: "
    )
    ch = input(
        "\n1. To authenticate it right now, like a good master! ^o^\n2. To skip and not be cool to me, like a bad master! U_U\n"
    )
    if ch == '1':
        gmail_authentication()
    elif ch == '2':
        pass
    else:
        print("Invalid Input, Skipping!")
    cipher_suite = Fernet(key)
    usr_info_dic['name'] = cipher_suite.encrypt(nm)
    GND_FEMALE = ["girl", 'miss', 'missus', 'mrs', 'female', 'lady', 'woman']
    GND_MALE = ["boy", "master", "mister", "mr", "male", "lodu", "man"]
    if gnd.lower() in GND_FEMALE:
        usr_info_dic['gender'] = cipher_suite.encrypt(b"Female")
    elif gnd.lower() in GND_MALE:
        usr_info_dic['gender'] = cipher_suite.encrypt(b"Male")
    else:
        usr_info_dic['gender'] = cipher_suite.encrypt(b"Others")
    usr_info_dic["asst_password"] = cipher_suite.encrypt(hashed_pswd)
    usr_info_dic['email'] = cipher_suite.encrypt(eml)
    info_in(usr_info_dic)
    voice_io.show(
        "Well then you're good to go! Just press Enter/Return to continue!",
        end="")
    invoice.inpt("", iterate=False)
    return key, nm.decode("utf-8")
Beispiel #4
0
def note_write():
    note_rem_create()
    con = sql.connect(get_dirs.DB_NOTES_REMINDERS)
    cur = con.cursor()
    voice_io.show("Okay so you wanna enter a new note? Here ya go!")
    x1 = invoice.inpt("Enter Note Here: ", processed=False)
    cur.execute(
        "insert into notes values(datetime('now', 'localtime'), '%s');" % x1)
    voice_io.show("Note Saved Successfully!")
    con.commit()
    con.close()
Beispiel #5
0
 def vc_vol_inp():
     try:
         as_vc_vol = float(
             input("Enter the assistant voice volume (0-1): "))  #DEF=1.0
         if as_vc_vol >= 0 and as_vc_vol <= 1:
             return as_vc_vol
         else:
             voice_io.show("Invalid Input! Please Try Again!")
             return vc_vol_inp()
     except:
         voice_io.show("Invalid Input! Please Try Again!")
Beispiel #6
0
 def vc_gnd_inp():
     as_vc_gnd = input(
         "Enter the assistant voice gender (Male/Female): ")  #DEF=MALE
     vc_gnd1 = ["male", "man", "boy", "mister"]
     vc_gnd2 = ["female", "girl", "miss", "missus", "mrs", "woman"]
     if as_vc_gnd.lower() in vc_gnd1:
         return "Male"
     elif as_vc_gnd in vc_gnd2:
         return "Female"
     else:
         voice_io.show("Invalid Input! Please Try Again!")
         vc_gnd_inp()
Beispiel #7
0
def weather_curr():      
    base_url = "http://api.openweathermap.org/data/2.5/weather?"
    url = base_url + "&q=" + ct + "&appid=" + api
    response = requests.get(url)  
    x = response.json()  
    if x["cod"] == "404":  
        voice_io.show("Oops! it looks like i ran into a problem fetching your request, maybe try again later?")
    else:
        y = x["main"]  
        curr_temperature = y["temp"]  
        curr_pressure = y["pressure"]  
        curr_humidity = y["humidity"]  
        z = x["weather"]  
        weather_desc = z[0]["description"]  
        voice_io.show(f"The current temperatre in {ct} is {str(round(curr_temperature-273))}°C" + ". It's a " +str(weather_desc))  
Beispiel #8
0
def pda_help():
    voice_io.show(
        "Select from the following Settings which can i help you with?")
    voice_io.show("1. Assistant Settings Update")
    voice_io.show("2. Assitant Settings Reset")
    voice_io.show("3. User Data Update")
    x = invoice.inpt("Enter Choice: ")
    if x == "1":
        assistant_settings.ass_settings_update()
    elif x == "2":
        assistant_settings.ass_settings_reset()
    elif x == "3":
        usr_signup.info_update()
    else:
        voice_io.show(
            "Invalid Input! Please make sure you're entering a valid input!")
Beispiel #9
0
 def vc_lng_inp():
     try:
         as_vc_lng = input("Enter the assistant voice language: ")
         vc_lng1 = [
             "en-in", "english", "english india", "english united states",
             "english us"
         ]
         if as_vc_lng.lower() in vc_lng1:
             as_vc_lng = "english"
             #as_vc_lng_id=11
             return as_vc_lng
         else:
             as_vc_lng = "Default"
             return as_vc_lng
     except:
         voice_io.show("Invalid Input! Please Try Again!")
         vc_lng_inp()
Beispiel #10
0
def userSetup():
    return_val = True
    voice_io.show("""Hello There!

I am Kori, your Personal Virtual Assistant.
I will be present at all times, waiting for your command.
You can ask me to do whatever you want! 
Want to get some work done and need help to ease your burden? 
or Check in on the latest news headlines and match scores 
or Wanna lighten up your mood with some funny jokes 
or Tune in to your favorite podcasts or songs, all of this and more 
without lifting a single finger? Well that's what I was made for :)

But first, please do let me know you better.
    
The voice output feature is turned off by default as I'm still in
my fetal phase and my voice box, so to speak, is not ready yet! ;)
But if you still want to use it, type 'enable sound' and ENDURE!!! 

By the way, I will be taking Text Input (as my ears too are... you know) 
but you can always use the command 'voice' if you would prefer to speak 
your commands instead.

Now then, Please Press Enter/Return to continue.
""")
    command = invoice.inpt(iterate=False)

    if command == "":
        pass
    else:
        voice_io.show(
            "Sorry I don't get it, I'm continuing with the Setup Process.")

    if not os.path.exists(get_dirs.PATH_USR_DATA):
        os.mkdir(get_dirs.PATH_USR_DATA)
    global key, usr_name
    key, usr_name = usr_signup.main(operation="new")
Beispiel #11
0
def fetch_joke(st):
    res_j = requests.get('https://icanhazdadjoke.com/',
                         headers={"Accept": "application/json"})
    if res_j.status_code == requests.codes.ok:
        voice_io.show(st)
        voice_io.show(str(res_j.json()['joke']))

    else:
        voice_io.show(
            "Oops! It looks like i ran out of my jokes, why don't you try again later."
        )
Beispiel #12
0
def fetch_password():
    pswd = bytes(getpass.getpass(
        voice_io.show("\nPlease enter your password. ", show_output=False) +
        "\nPassword: "******"utf-8")  #use password
    salt = b'$2b$12$3hbla5Xs2Ekx9SGVYfWQuO'
    hashed_pswd = bcrypt.hashpw(pswd, salt)
    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=salt,
        iterations=100000,
    )
    global key
    key = base64.urlsafe_b64encode(kdf.derive(hashed_pswd))
    global usr_name
    usr_name = False
    usr_name = usr_signup.main(operation="fetch", data_type="name", key=key)
Beispiel #13
0
def weather_forec():
    voice_io.show("Sorry i am currently restricted to show weather forecast for tomorrow only. \nLook out for future updates and see if my handcuffs are set free. Here's tomorrow's weather forecast anyway.")
    owm = OWM(api)
    mgr=owm.weather_manager()
    loc = mgr.weather_at_place(ct)
    weather = loc.weather
    temp = weather.temperature(unit='celsius')
    for key,val in temp.items():
        if key=="temp":
            voice_io.show(f'\nThe temperature tommorow will be around {val}°C.')
        else:
            continue
    loa = mgr.forecast_at_place(ct,'3h')
    tomorrow=timestamps.tomorrow()
    forecasttt=loa.get_weather_at(tomorrow)
    status=(forecasttt.status)
    voice_io.show(f'And the sky would remain {status}')
Beispiel #14
0
def deleteFolderUnspecified():
    search_dir = ""
    voice_io.show("Which folder do you want to delete?")
    folder_name = invoice.inpt(processed=False)
    voice_io.show(
        f"Where would you like me to search for the folder, {folder_name}?\n1. Desktop\n2. Downloads\n3. Documents\n4. Music\n5. Pictures\n6. Videos\n7. Entire home directory"
    )
    locate = invoice.inpt().lower()
    if locate in locate_desktop:
        search_dir = desktop

    elif locate in locate_documents:
        search_dir = documents

    elif locate in locate_downloads:
        search_dir = downloads

    elif locate in locate_home:
        search_dir = home

    elif locate in locate_music:
        search_dir = music

    elif locate in locate_pictures:
        search_dir = pictures

    elif locate in locate_videos:
        search_dir = videos

    else:
        voice_io.show(
            "Sorry but i can not find the given directory, going forward with the entire home directory!"
        )
        search_dir = home

    file_op.deleteFolder(folder_name=folder_name, search_dir=search_dir)
Beispiel #15
0
def reminder_read():
    note_rem_create()
    con = sql.connect(get_dirs.DB_NOTES_REMINDERS)
    cur = con.cursor()
    voice_io.show(
        "Hey there! Here's where all your reminders are stored! Yes I Know, I Know that i am not notifying you of your set reminders when the date and time comes but that's not a bug you see, my developers are still working on that feature and you'll see it in the near future ;) so just for now you have to keep checking in here to keep up to date with your saved reminders. Sorry again for the inconvienience caused but anyway,"
    )
    voice_io.show("\nWhat reminders do you want to read?")
    voice_io.show("1. Past Reminders")
    voice_io.show("2. Future/Upcoming Reminders")
    cho = input("Enter Choice: ")
    if cho == "1":
        cur.execute(
            "select rowid, datetime_added, reminder, datetime_tbn from past_reminders;"
        )
        c = cur.fetchall()
        if c == []:
            voice_io.show(
                "Well it looks like you don't have any past reminders. Is that a good thing or a bad thing? Hmmm"
            )

        else:
            voice_io.show("Here are all your past reminders: ")
            print()
            voice_io.show(
                tabulate.tabulate(c,
                                  headers=[
                                      "ReminderID", "Date and Time Added",
                                      "Reminder",
                                      "Date and Time to be Notified"
                                  ]))
            print()

            prmpt = input("Would you like to delete past reminders? ")
            prmpt = prmpt.lower()
            if prmpt in ['yeah', 'yep', 'yes', 'ok']:
                remid = input(
                    "Please Enter the ReminderID of the Reminder you wanna delete or type 'all' if you want to delete all of them: "
                )
                if remid.isnumeric() != True:
                    remid = remid.lower()
                    if remid == 'all':
                        cur.execute("delete from past_reminders;")
                        con.commit()
                        voice_io.show(
                            "All past reminders deleted successfully!")
                    else:
                        voice_io.show("Invalid Input!")

                else:
                    remid = int(remid)
                    try:
                        cur.execute(
                            "delete from past_reminders where rowid=%i;" %
                            (remid))
                        con.commit()
                        voice_io.show("Reminder Deleted Successfully!")
                    except:
                        voice_io.show(
                            "Sorry i couldn't process your request at the moment, maybe because you're not entering a valid ReminderID or something else, why don't you try again later!?"
                        )

            elif prmpt in ['no', 'nah', 'nope', 'not really']:
                voice_io.show("Alright!")

            else:
                print("Okay!")

    elif cho == "2":
        cur.execute(
            "select rowid, datetime_added, reminder, datetime_tbn from future_reminders;"
        )
        c = cur.fetchall()
        if c == []:
            voice_io.show(
                "Well it looks like you don't have any upcoming reminders. Is that a good thing or a bad thing? Hmmm"
            )

        else:
            voice_io.show("Here are all your upcoming/future reminders: ")
            print()
            voice_io.show(
                tabulate.tabulate(c,
                                  headers=[
                                      "ReminderID", "Date and Time Added",
                                      "Reminder",
                                      "Date and Time to be Notified"
                                  ]))
            print()

            prmpt = input("Would you like to edit or delete these reminders? ")
            prmpt = prmpt.lower()
            if prmpt in ['yeah', 'yep', 'yes', 'ok']:
                ch = int(
                    input(
                        "\nAnd what do you want to do really? \n1. Edit \n2. Delete \nEnter Choice: "
                    ))
                if ch == 1:
                    remid = int(
                        input(
                            "Please Enter the ReminderID of the Reminder you wanna edit: "
                        ))
                    ch2 = int(
                        input(
                            "And What exactly do you wanna edit? \n1. Reminder Content \n2. Reminder Date and Time \nEnter Choice: "
                        ))
                    if ch2 == 1:
                        newrem = input("Okay Enter the new updated Reminder: ")
                        try:
                            cur.execute(
                                "update future_reminders set reminder='%s' where rowid=%i;"
                                % (newrem, remid))
                            con.commit()
                            voice_io.show("Reminder Updated Successfully!")
                        except:
                            voice_io.show(
                                "Sorry i couldn't process your request at the moment, maybe because you're not entering a valid NoteID or something else, why don't you try again later!?"
                            )

                    elif ch2 == 2:
                        newdatetime = input(
                            "Okay Enter the new Date and Time (YYYY-MM-DD HH:MM:SS): "
                        )
                        try:
                            cur.execute(
                                "update future_reminders set datetime_tbn='%s' where rowid=%i;"
                                % (newdatetime, remid))
                            con.commit()
                            voice_io.show("Reminder Updated Successfully!")
                        except:
                            voice_io.show(
                                "Sorry i couldn't process your request at the moment, maybe because you're not entering a valid NoteID or something else, why don't you try again later!?"
                            )

                    else:
                        voice_io.show("Invalid Input")

                elif ch == 2:
                    remid = input(
                        "Please Enter the ReminderID of the Reminder you wanna delete or type 'all' if you want to delete all of them: "
                    )
                    if remid.isnumeric() != True:
                        remid = remid.lower()
                        if remid == 'all':
                            cur.execute("delete from future_reminders;")
                            con.commit()
                            voice_io.show(
                                "All future reminders deleted successfully!")
                        else:
                            voice_io.show("Invalid Input!")

                    else:
                        remid = int(remid)
                        try:
                            cur.execute(
                                "delete from future_reminders where rowid=%i;"
                                % (remid))
                            con.commit()
                            voice_io.show("Reminder Deleted Successfully!")
                        except:
                            voice_io.show(
                                "Sorry i couldn't process your request at the moment, maybe because you're not entering a valid ReminderID or something else, why don't you try again later!?"
                            )

            elif prmpt in ['no', 'nah', 'nope', 'not really']:
                voice_io.show("Alright!")

            else:
                print("Okay!")

    else:
        voice_io.show('Invalid Input!')

    con.close()
Beispiel #16
0
def websearch(query):
    query = query.lower()
    if 'what is' in query:
        try:
            voice_io.show(wolfy(query))

        except:
            try:
                voice_io.show('Searching Wikipedia...\n')
                query1 = query.replace("what is ", "")
                results = wikipedia.summary(query1)
                voice_io.show("According to Wikipedia,")
                voice_io.show(results)
            except:
                voice_io.show(
                    f"Could not find any results relating to {query1}, \nplease make sure you're entering a valid input!"
                )

    elif 'meaning of' in query:
        try:
            voice_io.show('Searching Wikipedia...')
            query1 = query.replace("meaning of ", "")
            results = wikipedia.summary(query1, sentences=1)
            voice_io.show("According to Wikipedia")
            voice_io.show(results)
        except:
            try:
                voice_io.show(wolfy(query))
            except:
                voice_io.show(
                    f"Could not find any results relating to {query1}, \nplease make sure you're entering a valid input!"
                )

    elif 'define' in query:
        try:
            voice_io.show('Searching Wikipedia...')
            query1 = query.replace("define ", "")
            results = wikipedia.summary(query1, sentences=1)
            voice_io.show("According to Wikipedia")
            voice_io.show(results)
        except:
            try:
                voice_io.show(wolfy(query))
            except:
                voice_io.show(
                    f"Could not find any results relating to {query1}, \nplease make sure you're entering a valid input!"
                )

    elif 'search' in query:
        query = query.replace("search ", "")
        voice_io.show(f"Searching google for '{query}'")
        query = query.replace(" ", "+")
        webbrowser.open(f"https://www.google.com/search?q={query}")

    elif "where is" in query:
        query = query.replace("where is ", "")
        voice_io.show(f"Searching google maps for '{query}'")
        location = query
        voice_io.show("You asked to locate", location, "and here you go!")
        webbrowser.open("https://www.google.nl/maps/place/" + location + "")

    elif "open website" in query:
        reg_ex = re.search('open website (.+)', query)
        if reg_ex:
            domain = reg_ex.group(1)
            url = 'https://www.' + domain + ".com"
            webbrowser.open(url)
            voice_io.show(
                'The website you have requested will now be opened for you.')
        else:
            pass

    elif 'youtube' in query:
        voice_io.show("Alright, opening Youtube right away!\n")
        webbrowser.open("https://www.youtube.com")

    elif 'google' in query:
        voice_io.show("Alright, opening Google right away!\n")
        webbrowser.open("https://www.google.com")

    elif 'instagram' in query:
        voice_io.show("Alright, opening Instagram right away!")
        webbrowser.open("https://www.instagram.com")

    elif 'twitter' in query:
        voice_io.show("Alright, opening Twitter right away!")
        webbrowser.open("https://www.twitter.com")

    elif 'reddit' in query:
        voice_io.show("Alright, opening Reddit right away!")
        webbrowser.open("https://www.reddit.com")

    elif 'facebook' in query:
        voice_io.show("Alright, opening Facebook right away!")
        webbrowser.open("https://www.facebook.com")

    else:
        try:
            voice_io.show(wolfy(query))
        except:
            voice_io.show(
                "Uh-oh! It looks like i ran into some problems, why don't you try again later?"
            )
Beispiel #17
0
def info_update():
    global u
    while True:
        voice_io.show("What do you wanna Update?")
        voice_io.show("1. Name")
        voice_io.show("2. Gender")
        voice_io.show("3. Email")
        voice_io.show("5. Nothing (Exit)")
        ch = input("What entry do you want to update? ")
        if ch == '1':
            u = 'name'
            in_upd_entr()
            break
        elif ch == '2':
            u = 'gender'
            in_upd_entr()
            break
        elif ch == '3':
            u = 'email'
            in_upd_entr()
            break
        elif ch == '4':
            u = 'password'
            in_upd_entr()
            break
        elif ch == '5':
            return
        else:
            voice_io.show("Invalid Input!")
            return
    voice_io.show("Data Updated Successfully!")
Beispiel #18
0
def inpt(text=">>> ", audio_io=True, iterate=True, processed=True):
    if audio_io:
        from pac import voice_io
        #import voice_io

        while True:
            try:
                entered_data = input(text)
                # voice_io.show("input = ",entered_data)

                if processData(entered_data) == "voice":
                    i = 0
                    voice_data = False
                    while not voice_data:
                        try:
                            voice_io.show("I am listening......")
                            voice_data = entered_data = voice_io.voice_in()
                            i += 1
                            if i >= 1:
                                voice_io.show(
                                    "\nSorry, could not get that! Please try again..\n"
                                )

                        except KeyboardInterrupt:  #stops voice input when ctrl+c is pressed
                            voice_io.show("\nStopped listening")
                            entered_data = ""
                            voice_data = True

                elif entered_data == "":
                    if not iterate:
                        return ""
                    continue

                elif processData(entered_data).lower() == "disable sound":
                    assistant_settings.disableSound()
                    if not iterate:
                        return ""

                    voice_io.show(
                        "Sound has been disabled! You can continue with your operation"
                    )
                    continue

                elif processData(entered_data).lower() == "enable sound":
                    assistant_settings.enableSound()
                    if not iterate:
                        return ""

                    voice_io.show(
                        "Sound has been enabled! You can continue with your operation"
                    )
                    continue

                elif "clear" in processData(entered_data).lower(
                ) or processData(entered_data).lower() in "clrcls":
                    return "clear"

                elif processData(entered_data).lower() in [
                        "exit", "quit", "end", "bye", "good bye", "goodbye",
                        "tata"
                ]:
                    #voice_io.show(entered_data.lower() in "exitquitend")
                    voice_io.show("\nBye and have a nice day!")
                    exit()

                else:
                    if processed:
                        entered_data = processData(entered_data)

                    return entered_data

            except KeyboardInterrupt:  #exits from the program when ctrl+c is pressed
                voice_io.show("\nBye and have a nice day!")
                exit()

    else:
        entered_data = input(text)
        if processed:
            entered_data = processData(entered_data)

        return entered_data
Beispiel #19
0
def main():
    clear.clear()
    voice_io.show(
        "*NOTE: The news feature is still under-development and so it might be prone to errors. Please report any such occurences if you find one! Thanks @Prabhat.\n"
    )
    voice_io.show(
        "Here comes the news boy! Haha How can i help you today? Please Press: "
    )
    voice_io.show("1. For Today's top headlines.")
    voice_io.show("2. For Top headlines in a category.")
    voice_io.show("3. For Top headlines in another country.")
    voice_io.show("4. To Search for News.")
    voice_io.show("5. To go back.")
    ch = invoice.inpt("Here: ")
    if ch == '1':
        headlines()

    elif ch == '2':
        catg = invoice.inpt(
            "What Category trending news do you want to see? ['business', 'entertainment', 'general', 'health', 'science', 'sports', 'technology']: "
        )
        if catg not in [
                'business', 'entertainment', 'general', 'health', 'science',
                'sports', 'technology'
        ]:
            voice_io.show(
                "I'm not sure if i can do that! Anyway here's the general trending news!"
            )
            headlines()
        else:
            headlines(catg=catg)

    elif ch == '3':
        cnt = invoice.inpt(
            "Which Country's trending news do you want to see?: ")
        cnt_code = cnt_iso3166(cnt)
        headlines(cnt=cnt_code)

    elif ch == '4':
        search_news()

    elif ch == '5':
        return

    else:
        voice_io.show("Invalid Input!")
Beispiel #20
0
def file_opener(obj_name, search_dir):
    folder_search_results = folderSearch(obj_name, search_dir)
    file_search_results = fileSearch(obj_name, search_dir)
    if folder_search_results != [] and file_search_results != 0:
        count_files = len(file_search_results)
        count_folders = len(folder_search_results)
        voice_io.show(
            f"Found {count_files} files and {count_folders} folders matching the given name! They are :-"
        )
        sno = 1
        for i in file_search_results:
            voice_io.show(f"{sno}. file '{i['file']}', inside '{i['root']}'")
            sno += 1

        for i in folder_search_results:
            voice_io.show(
                f"{sno}. folder '{i['folder']}', inside '{i['root']}'")
            sno += 1
        voice_io.show(
            "Select the number of the file/folder which you would like to open."
        )
        choice = int(invoice.inpt())
        choice -= 1
        try:
            if choice in range(count_files):
                f_name = file_search_results[choice]['file']
                parent_dir = file_search_results[choice]['root']
                voice_io.show(
                    f"Opening file '{f_name}' from '{parent_dir}'.....")
                full_dir = parent_dir + "/" + f_name
                open_file(full_dir)

            elif choice - (count_files) in range(count_folders):
                choice -= count_files
                f_name = folder_search_results[choice]['folder']
                parent_dir = folder_search_results[choice]['root']
                voice_io.show(
                    f"Opening folder '{f_name}' from '{parent_dir}' in the Files Explorer....."
                )
                full_dir = parent_dir + "/" + f_name
                open_file(full_dir)

            else:
                voice_io.show(
                    "Opening failed : Sorry, but the entered number is not within the range of available options."
                )

        except SyntaxError or TypeError:
            voice_io.show(
                "Opening failed : Sorry, but your entered data is not a number."
            )

    elif folder_search_results != []:
        if len(folder_search_results) == 1:
            voice_io.show(
                f"Opening folder '{folder_search_results[0]['folder']}' from '{folder_search_results[0]['root']}' in the Files Explorer....."
            )
            open_file(folder_search_results[0]["root"] + "/" +
                      folder_search_results[0]["folder"])

        else:
            sno = 1
            for i in folder_search_results:
                voice_io.show(
                    f"{sno}. folder '{i['folder']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the folder which you would like to open."
            )
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = folder_search_results[choice]['folder']
                parent_dir = folder_search_results[choice]['root']
                voice_io.show(
                    f"Opening folder '{f_name}' from '{parent_dir}' in the Files Explorer....."
                )
                full_dir = parent_dir + "/" + f_name
                open_file(full_dir)

            except IndexError:
                voice_io.show(
                    "Opening failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Opening failed : Sorry, but your entered data is not a number."
                )

    elif file_search_results != []:
        if len(file_search_results) == 1:
            voice_io.show(
                f"Opening file '{file_search_results[0]['file']}' from '{file_search_results[0]['root']}'....."
            )
            open_file(file_search_results[0]["root"] + "/" +
                      file_search_results[0]["file"])

        else:
            sno = 1
            for i in file_search_results:
                voice_io.show(
                    f"{sno}. file '{i['file']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the file which you would like to open.")
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = file_search_results[choice]['file']
                parent_dir = file_search_results[choice]['root']
                voice_io.show(
                    f"Opening file '{f_name}' from '{parent_dir}'.....")
                full_dir = parent_dir + "/" + f_name
                open_file(full_dir)

            except IndexError:
                voice_io.show(
                    "Opening failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Opening failed : Sorry, but your entered data is not a number."
                )

    else:
        voice_io.show(f"Sorry, could not find file/folder '{obj_name}'!")
Beispiel #21
0
def move(obj_name, search_dir, dest_dir):
    dest_dir = get_dirs.HOME + "/" + dest_dir
    if not os.path.isdir(dest_dir):
        os.mkdir(dest_dir)

    folder_search_results = folderSearch(obj_name, search_dir)
    file_search_results = fileSearch(obj_name, search_dir)
    if folder_search_results != [] and file_search_results != 0:
        count_files = len(file_search_results)
        count_folders = len(folder_search_results)
        voice_io.show(
            f"Found {count_files} files and {count_folders} folders matching the given name! They are :-"
        )
        sno = 1
        for i in file_search_results:
            voice_io.show(f"{sno}. file '{i['file']}', inside '{i['root']}'")
            sno += 1

        for i in folder_search_results:
            voice_io.show(
                f"{sno}. folder '{i['folder']}', inside '{i['root']}'")
            sno += 1
        voice_io.show(
            "Select the number of the file/folder which you would like to move."
        )
        choice = int(invoice.inpt())
        choice -= 1
        try:
            if choice in range(count_files):
                f_name = file_search_results[choice]['file']
                parent_dir = file_search_results[choice]['root']
                voice_io.show(
                    f"Moving file '{f_name}' from '{parent_dir}' to '{dest_dir}'....."
                )
                shutil.copy2(parent_dir + "/" + f_name, dest_dir)
                os.remove(parent_dir + "/" + f_name)
                voice_io.show(
                    f"Successfully moved '{f_name}' to '{dest_dir}'!")

            elif choice - (count_files) in range(count_folders):
                choice -= (count_files)
                f_name = folder_search_results[choice]['folder']
                parent_dir = folder_search_results[choice]['root']
                voice_io.show(
                    f"Moving folder '{f_name}' from '{parent_dir}' to '{dest_dir}'....."
                )
                copytree(parent_dir + "/" + f_name, dest_dir)
                shutil.rmtree(parent_dir + "/" + f_name)
                voice_io.show(
                    f"Successfully moved '{f_name}' to '{dest_dir}'!")

            else:
                voice_io.show(
                    "Moving failed : Sorry, but the entered number is not within the range of available options."
                )

        except SyntaxError or TypeError:
            voice_io.show(
                "Moving failed : Sorry, but your entered data is not a number."
            )

    elif folder_search_results != []:
        if len(folder_search_results) == 1:
            voice_io.show(
                f"Moving folder '{folder_search_results[0]['folder']}' from '{folder_search_results[0]['root']}' to '{dest_dir}'....."
            )
            copytree(
                folder_search_results[0]["root"] + "/" +
                folder_search_results[0]["folder"], dest_dir)
            shutil.rmtree(folder_search_results[0]["root"] + "/" +
                          folder_search_results[0]["folder"])
            voice_io.show(
                f"Successfully moved '{folder_search_results[0]['file']}' to '{dest_dir}'!"
            )

        else:
            sno = 1
            for i in folder_search_results:
                voice_io.show(
                    f"{sno}. folder '{i['folder']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the folder which you would like to move."
            )
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = folder_search_results[choice]['folder']
                parent_dir = folder_search_results[choice]['root']
                voice_io.show(
                    f"Moving folder '{f_name}' from '{parent_dir}' to '{dest_dir}'....."
                )
                copytree(parent_dir + "/" + f_name, dest_dir)
                shutil.rmtree(parent_dir + "/" + f_name)
                voice_io.show(
                    f"Successfully moved '{f_name}' to '{dest_dir}'!")

            except IndexError:
                voice_io.show(
                    "Moving failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Moving failed : Sorry, but your entered data is not a number."
                )

    elif file_search_results != []:
        if len(file_search_results) == 1:
            voice_io.show(
                f"Moving file '{file_search_results[0]['file']}' from '{file_search_results[0]['root']}' to '{dest_dir}''....."
            )
            shutil.copy2(
                file_search_results[0]["root"] + "/" +
                file_search_results[0]["file"], dest_dir)
            os.remove(file_search_results[0]["root"] + "/" +
                      file_search_results[0]["file"])
            voice_io.show(
                f"Successfully moved '{file_search_results[0]['file']}' to '{dest_dir}'!"
            )

        else:
            sno = 1
            for i in file_search_results:
                voice_io.show(
                    f"{sno}. file '{i['file']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the file which you would like to copy.")
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = file_search_results[choice]['file']
                parent_dir = file_search_results[choice]['root']
                voice_io.show(
                    f"Moving file '{f_name}' from '{parent_dir}' to '{dest_dir}'....."
                )
                shutil.copy2(parent_dir + "/" + f_name, dest_dir)
                os.remove(parent_dir + "/" + f_name)
                voice_io.show(
                    f"Successfully moved '{f_name}' to '{dest_dir}'!")

            except IndexError:
                voice_io.show(
                    "Moving failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Moving failed : Sorry, but your entered data is not a number."
                )

    else:
        voice_io.show(f"Sorry, could not find file/folder '{obj_name}'!")
Beispiel #22
0
def note_read():
    note_rem_create()
    con = sql.connect(get_dirs.DB_NOTES_REMINDERS)
    cur = con.cursor()
    cur.execute("select rowid, date_added, note from notes;")
    c = cur.fetchall()
    if c == []:
        voice_io.show(
            "There are no notes to be shown, try making new notes! :)")
    else:
        voice_io.show("Here are all your notes: ")
        print()
        voice_io.show(
            tabulate.tabulate(
                c, headers=["NoteID", "Date and Time Added", "Note"]))
        print()
        prmpt = input("Would you like to delete or edit these notes? ")
        prmpt = prmpt.lower()
        if prmpt in ['yeah', 'yep', 'yes', 'ok']:
            ch = int(
                input(
                    "\nAnd what do you want to do really? \n1. Edit \n2. Delete \nEnter Choice: "
                ))
            if ch == 1:
                noteid = int(
                    input(
                        "Please Enter the NoteID of the Note you wanna edit: ")
                )
                newnote = input("Now enter the new updated note: ")
                try:
                    cur.execute("update notes set note='%s' where rowid=%i;" %
                                (newnote, noteid))
                    con.commit()
                    voice_io.show("Note Updated Successfully!")
                except:
                    voice_io.show(
                        "Sorry i couldn't process your request at the moment, maybe because you're not entering a valid NoteID or something else, why don't you try again later!?"
                    )

            elif ch == 2:
                noteid = int(
                    input(
                        "Please Enter the NoteID of the Note you wanna delete: "
                    ))
                try:
                    cur.execute("delete from notes where rowid=%i;" % (noteid))
                    con.commit()
                    voice_io.show("Note Deleted Successfully!")
                except:
                    voice_io.show(
                        "Sorry i couldn't process your request at the moment, maybe because you're not entering a valid NoteID or something else, why don't you try again later!?"
                    )

            else:
                voice_io.show("Invalid Input!")

        elif prmpt in ['no', 'nah', 'nope', 'not really']:
            voice_io.show("Alright!")

        else:
            print("Okay!")

    con.close()
Beispiel #23
0
def reminder_write():
    note_rem_create()
    con = sql.connect(get_dirs.DB_NOTES_REMINDERS)
    cur = con.cursor()
    x1 = invoice.inpt("Enter Reminder: ")
    x2 = invoice.inpt("Enter Date to be Notified (YYYY-MM-DD): ")
    x3 = input("Enter Time to be Notified (HH:MM:SS): ")
    x4 = x2 + ' ' + x3
    datetime_now = time_now()

    if x4 < datetime_now:
        prmpt = input(
            "Hey you are entering a reminder for a date and time that has already passed, are you sure you want to continue? "
        )
        prmpt = prmpt.lower()
        if prmpt in ['yeah', 'yep', 'yes', 'ok']:
            voice_io.show("Alright as you wish, master!")
            cur.execute(
                "insert into past_reminders values(datetime('now', 'localtime'), '%s', '%s');"
                % (x1, x4))
            voice_io.show("Reminder Saved Successfully!")
            con.commit()
        elif prmpt in ['no', 'nah', 'nope', 'not really']:
            voice_io.show("Okay!")
        else:
            voice_io.show("Invalid Input!")

    elif x4 > datetime_now:
        cur.execute(
            "insert into future_reminders values(datetime('now', 'localtime'), '%s', '%s');"
            % (x1, x4))
        voice_io.show("Reminder Saved Successfully!")
        con.commit()
        #reminder_remind()

    else:
        voice_io.show(
            "An internal error occurred while processing your request, please make sure you've entered the values correctly and try again!"
        )

    con.close()
Beispiel #24
0
def day():
    x=datetime.datetime.now().strftime("%A")
    voice_io.show(f"Today it is a {x}")
Beispiel #25
0
def deleteFolder(folder_name, search_dir):
    folder_search_results = folderSearch(folder_name, search_dir)
    if folder_search_results != []:
        if len(folder_search_results) == 1:
            invoice.inpt(
                "%s from %s will be permanently lost, press Enter to continue."
                % (folder_search_results[0]["folder"],
                   folder_search_results[0]["root"]),
                iterate=False)
            shutil.rmtree(folder_search_results[0]["root"] + "/" +
                          folder_search_results[0]["folder"])
            voice_io.show(folder_name, "has been deleted successfully!")

        else:
            n_results = len(folder_search_results)
            voice_io.show(
                f"Found {n_results} folder matching the given folder name! They are :-"
            )
            sno = 1
            for i in folder_search_results:
                voice_io.show(
                    f"{sno}. folder '{i['folder']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the folder which you would like to delete"
            )
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = folder_search_results[choice]['folder']
                parent_dir = folder_search_results[choice]['root']
                invoice.inpt(
                    f"'{f_name}' from '{parent_dir}' will be permanently lost, press Enter to continue.",
                    iterate=False)
                shutil.rmtree(parent_dir + "/" + f_name)
                voice_io.show(f"'{f_name}' has been deleted successfully!")

            except IndexError:
                voice_io.show(
                    "Deletion failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Deletion failed : Sorry, but your entered data is not a number."
                )

    else:
        voice_io.show(
            f"Sorry, could not find file '{folder_name}', please check if the file you named exists or\nhas been spelled correctly."
        )
Beispiel #26
0
def date():
    x = datetime.datetime.now().strftime("%d/%m/%Y")  
    voice_io.show(f"Today's date is {x} (DD/MM/YYYY)")
Beispiel #27
0
def rname(obj_name, new_name, search_dir):
    folder_search_results = folderSearch(obj_name, search_dir)
    file_search_results = fileSearch(obj_name, search_dir)
    new_file_name = ""
    new_ext = ""
    old_file_name = ""
    old_ext = ""

    if folder_search_results != [] and file_search_results != []:
        count_files = len(file_search_results)
        count_folders = len(folder_search_results)
        voice_io.show(
            f"Found {count_files} files and {count_folders} folders matching the given name! They are :-"
        )
        sno = 1
        for i in file_search_results:
            voice_io.show(f"{sno}. file '{i['file']}', inside '{i['root']}'")
            sno += 1

        for i in folder_search_results:
            voice_io.show(
                f"{sno}. folder '{i['folder']}', inside '{i['root']}'")
            sno += 1
        voice_io.show(
            "Select the number of the file/folder which you would like to rename."
        )
        choice = int(invoice.inpt())
        choice -= 1
        try:
            if choice in range(count_files):
                f_name = file_search_results[choice]['file']
                new_name = new_name.split('.')
                new_file_name = new_name[0]
                if len(new_name) > 2:
                    for i in range(1, len(new_name) - 2):
                        new_file_name += "." + new_name[i]

                if len(new_name) > 1:
                    new_ext = new_name[len(new_name) - 1]
                    if new_ext == new_file_name:
                        new_ext = ""

                if len(f_name.split(".")) > 1:
                    old_ext = f_name.split(".")[len(f_name.split(".")) - 1]
                    if new_ext == "" and old_ext != f_name.split('.')[0]:
                        new_ext = old_ext

                new_full_name = new_file_name + "." + new_ext

                parent_dir = file_search_results[choice]['root']
                voice_io.show(
                    f"Renaming file '{f_name}' from '{parent_dir}' to '{new_full_name}'....."
                )
                os.rename(parent_dir + "/" + f_name,
                          parent_dir + "/" + new_full_name)
                voice_io.show(
                    f"Successfully renamed '{f_name}' to '{new_full_name}'!")

            elif choice - (count_files) in range(count_folders):
                choice -= (count_files)
                f_name = folder_search_results[choice]['folder']
                parent_dir = folder_search_results[choice]['root']
                voice_io.show(
                    f"Renaming folder '{f_name}' from '{parent_dir}' to '{new_name}''....."
                )
                os.rename(parent_dir + "/" + f_name,
                          parent_dir + "/" + new_name)
                voice_io.show(
                    f"Successfully renamed '{f_name}' to '{new_name}'!")

            else:
                voice_io.show(
                    "Renaming failed : Sorry, but the entered number is not within the range of available options."
                )

        except SyntaxError or TypeError:
            voice_io.show(
                "Renaming failed : Sorry, but your entered data is not a number."
            )

    elif folder_search_results != []:
        if len(folder_search_results) == 1:
            parent_dir = folder_search_results[0]["root"]
            f_name = folder_search_results[0]["folder"]
            voice_io.show(
                f"Renaming folder '{folder_search_results[0]['folder']}' from '{folder_search_results[0]['root']}' to '{new_name}'....."
            )
            os.rename(parent_dir + "/" + f_name, parent_dir + "/" + new_name)
            voice_io.show(
                f"Successfully renamed '{folder_search_results[0]['folder']}' to '{new_name}'!"
            )

        else:
            sno = 1
            for i in folder_search_results:
                voice_io.show(
                    f"{sno}. folder '{i['folder']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the folder which you would like to rename."
            )
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = folder_search_results[choice]['folder']
                parent_dir = folder_search_results[choice]['root']
                voice_io.show(
                    f"Renaming folder '{f_name}' from '{parent_dir}' to '{new_name}'....."
                )
                os.rename(parent_dir + "/" + f_name,
                          parent_dir + "/" + new_name)
                voice_io.show(
                    f"Successfully renamed '{f_name}' to '{new_name}'!")

            except IndexError:
                voice_io.show(
                    "Renaming failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Renaming failed : Sorry, but your entered data is not a number."
                )

    elif file_search_results != []:
        if len(file_search_results) == 1:
            parent_dir = file_search_results[0]["root"]
            f_name = file_search_results[0]["file"]
            new_name = new_name.split('.')
            new_file_name = new_name[0]
            if len(new_name) > 2:
                for i in range(1, len(new_name) - 2):
                    new_file_name += "." + new_name[i]

            if len(new_name) > 1:
                new_ext = new_name[len(new_name) - 1]
                if new_ext == new_file_name:
                    new_ext = ""

            if len(f_name.split(".")) > 1:
                old_ext = f_name.split(".")[len(f_name.split(".")) - 1]
                if new_ext == "" and old_ext != f_name.split('.')[0]:
                    new_ext = old_ext

            new_full_name = new_file_name + "." + new_ext

            voice_io.show(
                f"Renaming file '{file_search_results[0]['file']}' from '{file_search_results[0]['root']}' to '{new_full_name}''....."
            )
            os.rename(parent_dir + "/" + f_name,
                      parent_dir + "/" + new_full_name)
            voice_io.show(
                f"Successfully renamed '{file_search_results[0]['file']}' to '{new_full_name}'!"
            )

        else:
            sno = 1
            for i in file_search_results:
                voice_io.show(
                    f"{sno}. file '{i['file']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the file which you would like to rename."
            )
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = file_search_results[choice]['file']
                new_name = new_name.split('.')
                new_file_name = new_name[0]
                if len(new_name) > 2:
                    for i in range(1, len(new_name) - 2):
                        new_file_name += "." + new_name[i]

                if len(new_name) > 1:
                    new_ext = new_name[len(new_name) - 1]
                    if new_ext == new_file_name:
                        new_ext = ""

                if len(f_name.split(".")) > 1:
                    old_ext = f_name.split(".")[len(f_name.split(".")) - 1]
                    if new_ext == "" and old_ext != f_name.split('.')[0]:
                        new_ext = old_ext

                new_full_name = new_file_name + "." + new_ext

                parent_dir = file_search_results[choice]['root']
                voice_io.show(
                    f"Renaming file '{f_name}' from '{parent_dir}' to '{new_full_name}'....."
                )
                os.rename(parent_dir + "/" + f_name,
                          parent_dir + "/" + new_full_name)
                voice_io.show(
                    f"Successfully renamed '{f_name}' to '{new_full_name}'!")

            except IndexError:
                voice_io.show(
                    "Renaming failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Renaming failed : Sorry, but your entered data is not a number."
                )

    else:
        voice_io.show("Sorry, could not find file/folder '{obj_name}'!")
Beispiel #28
0
def search_news():
    clear.clear()
    voice_io.show(
        "\nFor advanced news search please fill in the following (Note - Those fields with an asterisk before their names are optional and so are those with a default something specified, please leave them empty if you don't intend to use them!)"
    )
    qry = invoice.inpt(
        """\nKeywords or phrases to search for in the news articles (Note - Surround phrases with quotes ('/\") for exact matches, 
Prepend words or phrases that must appear with a + symbol. Eg: +bitcoin, Prepend words that must not appear with a - symbol. Eg: -bitcoin. 
Alternatively you can use the AND / OR / NOT keywords, and optionally group these with parenthesis. Eg: crypto AND (ethereum OR litecoin) NOT bitcoin.): """
    )
    params = {'q': qry}
    sort = input(
        "Sort By ['relevancy', 'popularity', 'publishedAt'] (default is 'publishedAt', it is for the newest articles first): "
    )
    sort = sort.lower()
    if sort not in ['relevancy', 'popularity', 'publishedAt']:
        sort = 'publishedAt'
    params['sortBy'] = sort
    catg = input(
        "Category of the news articles ['business', 'entertainment', 'general', 'health', 'science', 'sports', 'technology'] (default is 'general'): "
    )
    catg = catg.lower()
    if catg not in [
            'business', 'entertainment', 'general', 'health', 'science',
            'sports', 'technology'
    ]:
        catg = 'general'
    params['category'] = catg
    cnt = input(
        "Country you want the articles to be about (default is your set location): "
    )
    if cnt == '':
        cnt = cnt_code
        params['country'] = cnt
    else:
        cnt = cnt_iso3166(cnt)
        params['country'] = cnt
    incldom = input(
        "*Include Domains (A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to): "
    )
    if incldom != '':
        params['domains'] = incldom
    excldom = input(
        "*Exclude Domains (A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to remove from the results.): "
    )
    if excldom != '':
        params['excludeDomains'] = excldom
    frm = input(
        "*Date and optional time for the oldest article (e.g. 2021-09-02 or 2021-09-02T03:29:09): "
    )
    if frm != '':
        params['from'] = frm
    to = input(
        "*Date and optional time for the newest article (e.g. 2021-09-02 or 2021-09-02T03:29:09): "
    )
    if to != '':
        params['to'] = to

    url = 'https://newsapi.org/v2/top-headlines?'
    for i in params.keys():
        s = f'{i}={params[i]}&'
        url += s
    url += f"apiKey={api}"
    voice_io.show(url)
    response = requests.get(url)
    r = response.json()

    try:
        items = []
        for i in r['articles']:
            item = (i['title'], i['description'], i['url'])
            items.append(item)

        if len(items) == 0:
            voice_io.show(
                "Sorry I couldn't find anything like that! Maybe you didn't specify it properly or maybe there just isn't anything regarding that right now, so try again later, maybe!?"
            )

        else:
            for i in range(len(items)):
                clear.clear()
                voice_io.show(f'[{i+1}]', items[i][0])
                time.sleep(1)
                voice_io.show(
                    "\nWhat would you like to do? \n1. Expand this headline and read a little more about it. \n2. Open this news piece in your browser. \n3. Skip to the next headline. \n4. Print all news headlines at once. \n5. Go back."
                )
                ch = invoice.inpt("Enter Choice: ")
                if ch == '1':
                    voice_io.show(items[i][1])
                    time.sleep(3)
                    ch1 = invoice.inpt(
                        "\nWould you like to know about this some more? I could open this up in your browser! (Y/N): "
                    )
                    if ch1.lower() == 'y':
                        voice_io.show("Here you go!\n")
                        webbrowser.open(items[i][2])
                    elif ch1.lower() == 'n':
                        voice_io.show("Okay! Onto the next one! \n")
                    else:
                        voice_io.show("Invalid Input!")

                elif ch == '2':
                    voice_io.show("Here you go!")
                    webbrowser.open(items[i][2])
                    invoice.inpt("Press Enter to continue to the next story!")
                    continue

                elif ch == '3':
                    continue

                elif ch == '4':
                    while True:
                        voice_io.show("Here you go!\n")
                        for j in range(len(items)):
                            voice_io.show(f'[{j+1}]', items[j][0])
                        time.sleep(3)
                        voice_io.show(
                            "\nWhat would you like to do now? \n1. Expand a specific headline and read a little more about it. \n2. Open a specific headline in your browser. \n3. Go back."
                        )
                        ch2 = invoice.inpt("Enter Choice: ")
                        if ch2 == '1':
                            inp = int(
                                invoice.inpt(
                                    "Enter the index of the news headline you'd like to know more about: "
                                ))
                            voice_io.show(items[inp - 1][0])
                            time.sleep(3)
                            ch3 = invoice.inpt(
                                "Would you like to know about this some more? I could open this up in your browser! (Y/N): "
                            )
                            if ch3.lower() == 'y':
                                #voice_io.show("Here you go!\n")
                                webbrowser.open(items[inp - 1][2])
                                invoice.inpt(
                                    "Press Enter to continue to the next story!"
                                )
                                continue
                            elif ch3.lower() == 'n':
                                ch3 = invoice.inpt(
                                    "\nDo you want to go back and read more news? (Y/N): "
                                )
                                if ch3.lower() == 'y':
                                    continue
                                else:
                                    return
                            else:
                                voice_io.show("Invalid Input!")
                            time.sleep(5)

                        elif ch2 == '2':
                            inp = int(
                                invoice.inpt(
                                    "Enter the index of the news headline you'd like to open up in your browser: "
                                ))
                            voice_io.show("Here you go!")
                            webbrowser.open(items[inp - 1][2])
                            ch3 = invoice.inpt(
                                "\nDo you want to go back and read more news? (Y/N): "
                            )
                            if ch3.lower() == 'y':
                                continue
                            else:
                                return

                        elif ch2 == '3':
                            return

                        else:
                            voice_io.show("Invalid Input!")

                elif ch == '5':
                    return

                else:
                    voice_io.show('Invalid Input!')

    except KeyError:
        voice_io.show(
            "Uh-oh! Looks like i ran into some error doing that! You sure everything's alright? Why not try again later!?"
        )
Beispiel #29
0
def playMusic(name, search_dir):
    from playsound import playsound
    file_search_results = fileSearch(file_name=name, search_dir=search_dir)
    music_files = []
    if len(file_search_results) > 0:
        for file_obj in file_search_results:
            f_name = file_obj['file']
            for ext in audio_file_ext:
                if ext in f_name:
                    music_files.append(file_obj)
                    break

        if len(music_files) == 1:
            f_name = music_files[0]['file']
            directory = music_files[0]['root']
            f_path = directory + '/' + f_name
            voice_io.show(
                f"Playing the audio file '{f_name}' from '{directory}'.")
            p = multiprocessing.Process(target=playsound, args=(f_path, ))
            p.start()
            input("Press ENTER to stop playback")
            p.terminate()
            voice_io.show(f"Stopped playing '{f_name}'.")

        elif len(music_files) > 1:
            sno = 1
            voice_io.show(
                f"Found {len(music_files)} files matching the given file name :-"
            )
            for i in music_files:
                voice_io.show(
                    f"{sno}. file '{i['file']}', inside '{i['root']}'")
                sno += 1
            voice_io.show(
                "Select the number of the audio file which you would like to play."
            )
            choice = int(invoice.inpt())
            choice -= 1
            try:
                f_name = music_files[choice]['file']
                directory = music_files[choice]['root']
                f_path = directory + "/" + f_name
                voice_io.show(
                    f"Playing the audio file '{f_name}' from '{directory}'.")
                p = multiprocessing.Process(target=playsound, args=(f_path, ))
                p.start()
                input("Press ENTER to stop playback")
                p.terminate()
                voice_io.show(f"Stopped playing '{f_name}'.")
            except IndexError:
                voice_io.show(
                    "Playback failed : Sorry, but the entered number is not within the range of available options."
                )

            except SyntaxError or TypeError:
                voice_io.show(
                    "Playback failed : Sorry, but your entered data is not a number."
                )

        else:
            voice_io.show(
                f"Sorry, could not find any audio file with the name '{name}'")

    else:
        voice_io.show(
            f"Sorry, could not find any audio file with the name '{name}'")
Beispiel #30
0
def headlines(cnt=cnt_code, catg='general'):
    url = ('https://newsapi.org/v2/top-headlines?'
           f'country={cnt}&'
           f'category={catg}&'
           f'apiKey={api}')
    #voice_io.show(url)
    response = requests.get(url)
    r = response.json()
    try:
        items = []
        for i in r['articles']:
            item = (i['title'], i['description'], i['url'])
            items.append(item)

        if len(items) == 0:
            voice_io.show(
                "Sorry I couldn't find anything like that! Maybe you didn't specify it properly or maybe there just isn't anything regarding that right now, so try again later, maybe!?"
            )

        else:
            for i in range(len(items)):
                clear.clear()
                voice_io.show(f'[{i+1}]', items[i][0])
                time.sleep(1)
                voice_io.show(
                    "\nWhat would you like to do? \n1. Expand this headline and read a little more about it. \n2. Open this news piece in your browser. \n3. Skip to the next headline. \n4. Print all news headlines at once. \n5. Go back."
                )
                ch = invoice.inpt("Enter Choice: ")
                if ch == '1':
                    voice_io.show(items[i][1])
                    time.sleep(3)
                    ch1 = invoice.inpt(
                        "\nWould you like to know about this some more? I could open this up in your browser! (Y/N): "
                    )
                    if ch1.lower() == 'y':
                        voice_io.show("Here you go!\n")
                        webbrowser.open(items[i][2])
                    elif ch1.lower() == 'n':
                        voice_io.show("Okay! Onto the next one! \n")
                    else:
                        voice_io.show("Invalid Input!")

                elif ch == '2':
                    voice_io.show("Here you go!")
                    webbrowser.open(items[i][2])
                    invoice.inpt("Press Enter to continue to the next story!")
                    continue

                elif ch == '3':
                    continue

                elif ch == '4':
                    while True:
                        clear.clear()
                        voice_io.show("Here you go!\n")
                        for j in range(len(items)):
                            voice_io.show(f'[{j+1}]', items[j][0])
                        time.sleep(3)
                        voice_io.show(
                            "\nWhat would you like to do now? \n1. Expand a specific headline and read a little more about it. \n2. Open a specific headline in your browser. \n3. Go back."
                        )
                        ch2 = invoice.inpt("Enter Choice: ")
                        if ch2 == '1':
                            inp = int(
                                invoice.inpt(
                                    "Enter the index of the news headline you'd like to know more about: "
                                ))
                            voice_io.show(items[inp - 1][0])
                            time.sleep(3)
                            ch3 = invoice.inpt(
                                "\nWould you like to know about this some more? I could open this up in your browser! (Y/N): "
                            )
                            if ch3.lower() == 'y':
                                #voice_io.show("Here you go!\n")
                                webbrowser.open(items[inp - 1][2])
                                continue
                            elif ch3.lower() == 'n':
                                ch3 = invoice.inpt(
                                    "\nDo you want to go back and read more news? (Y/N): "
                                )
                                if ch3.lower() == 'y':
                                    continue
                                else:
                                    return
                            else:
                                voice_io.show("Invalid Input!")
                            time.sleep(5)

                        elif ch2 == '2':
                            inp = int(
                                invoice.inpt(
                                    "Enter the index of the news headline you'd like to open up in your browser: "
                                ))
                            voice_io.show("Here you go!")
                            webbrowser.open(items[inp - 1][2])
                            ch3 = invoice.inpt(
                                "\nDo you want to go back and read more news? (Y/N): "
                            )
                            if ch3.lower() == 'y':
                                continue
                            else:
                                return

                        elif ch2 == '3':
                            return

                        else:
                            voice_io.show("Invalid Input!")

                elif ch == '5':
                    return

                else:
                    voice_io.show('Invalid Input!')

    except KeyError:
        voice_io.show(
            "Uh-oh! Looks like i ran into some error doing that! You sure everything's alright? Why not try again later!?"
        )