Beispiel #1
0
def start(cmd):

    if 'send mail' in cmd or ("send" in cmd and "mail" in cmd):
        the_voice.say_and_print("Preparing to send email...")
        send_mail.start()
        return 1

    elif 'read inbox' in cmd or ("read" in cmd and "inbox" in cmd):
        the_voice.say_and_print("Reading Email...")
        read_mail.start()
        return 1

    elif 'send whatsapp' in cmd or ("send" in cmd and "whatsapp" in cmd):
        the_voice.say_and_print("Preparing to send whatsapp...")
        send_whatsapp.start()
        return 1
    elif 'recognise object' in cmd or (
        ("recognise" in cmd or "recognize" in cmd) and "object" in cmd):
        the_voice.say_and_print("This feature is currently in beta mode!")
        # the_voice.say_and_print("Object recognition activating...")
        # obj_recog.start()
        return 1
    elif ("tell" in cmd and "weather" in cmd) or (
            "what" in cmd and "weather" in cmd) or ("how" in cmd
                                                    and "weather" in cmd):
        the_voice.say_and_print("Weather report:")
        weather_report.weather()
        return 1

    return 0
def save_unique():
    try:
        fr = open("data_files/start-processes.txt", "r")
    except:
        print("Start Processes not found!")
        return
    post = crr_pro()
    try:
        pre = ast.literal_eval(fr.read())
    except:
        print("Invalid data in start-processes.txt!")
        fr.close()
        return
    uni = dict()
    for i in post:
        if i not in pre:
            uni[i] = post[i]
    temp = list()
    # filtering
    for i in uni:
        if i in temp:
            del uni[i]
        else:
            if uni[i] is not None and "windows\\" not in uni[i].lower() and "windows\\\\" not in uni[i].lower():
                temp.append(i)
    fw = open("data_files/workspace.txt", 'w')
    fw.write(str(uni))
    fr.close()
    fw.close()
    the_voice.say_and_print("Success!")
Beispiel #3
0
def start(cmd):
    if "save workspace" in cmd or ("save" in cmd and "workspace" in cmd):
        the_voice.say_and_print("Saving workspace...")
        store_process.save_unique()
        return 1

    elif "set up workspace" in cmd or ("set" in cmd and "workspace" in cmd):
        the_voice.say_and_print("Setting workspace...")
        set_workspace.open_workspace_apps()
        return 1

    elif "search file" in cmd or ("search" in cmd and "file" in cmd):
        the_voice.say_and_print("Say the file name to search")
        temp = the_voice.listening()
        if temp is None:
            print("Sorry, didn't get you!")
            print(
                "Please say the name of file to search, or \"CANCEL\" to cancel"
            )
            while temp is not None:
                temp = the_voice.listening()
                temp = temp.lower()
                if temp == "cancel":
                    return 1
        temp = temp.lower()
        find.search(temp)
        return 1

    elif "open application" in cmd or ("open" in cmd and "app" in cmd):
        the_voice.say_and_print("Say the application name to open: ")
        temp = the_voice.listening()
        if temp is None:
            print("Sorry, didn't get you!")
            print(
                "Please say the name of file to search, or \"CANCEL\" to cancel"
            )
            while temp is not None:
                temp = the_voice.listening()
                temp = temp.lower()
                if temp == "cancel":
                    return 1
        temp = temp.lower()
        if ".exe" not in temp:
            temp = temp + ".exe"
        app_paths = find.search(temp, "endswith")
        for app_path in app_paths:
            set_workspace.open_app(app_path)
        if len(app_paths) == 0:
            the_voice.say_and_print("No such application found!")
        return 1
    elif "calculate" in cmd or ("run" in cmd and "calculator" in cmd) or (
            "open" in cmd and "calculator" in cmd):
        calculate.start()
        return 1

    return 0
def search(term, search_type="contains"):
    the_voice.say_and_print("Searching...")
    s.search(term, search_type)
    for i in s.results:
        print(i)
    the_voice.say_and_print(
        "Searched {:,d} records and found {:,d} matches".format(
            s.records, s.matches))
    print("Results saved in working directory as search_results.txt.")
    return s.results
def load_assistant(nm):
    if nm is None or type(nm) != type("abc"):
        print("No such profile!")
        return -1
    nm = nm.lower()
    try:
        fr = open("data_files/" + nm + "_assistant_settings.txt", "r")
    except:
        print("No such profile found!")
        the_voice.say_and_print(
            "Do you want to make a new assistant profile? (yes or no)")
        while True:
            ch = the_voice.listening()
            try:
                ch = ch.lower()
                if ch == "yes":
                    new_profile(nm)
                    return
                elif ch == "no":
                    return -1
                else:
                    print("Please say YES or NO!")
            except:
                print("Please say YES or NO!")
    try:
        temp = fr.read()
        data = eval(temp)
        voice = data["voice"]
        rate = data["rate"]
        name = data["name"]
        greet = data["greet"]
        failure = data["failure"]
        goodbye = data["goodbye"]
        assistant.set_vals(voice, rate, name, greet, failure, goodbye)
    except:
        print("Data in data_files/" + nm +
              "_assistant_settings.txt is corrupted!")
        the_voice.say_and_print(
            "Do you want to make a new assistant profile? (yes or no)")
        while True:
            ch = the_voice.listening()
            try:
                ch = ch.lower()
                if ch == "yes":
                    new_profile(nm)
                    fr.close()
                    return
                elif ch == "no":
                    fr.close()
                    return -1
                else:
                    print("Please say YES or NO!")
            except:
                print("Please say YES or NO!")
    fr.close()
def open_workspace_apps():
    try:
        fr = open("data_files/workspace.txt", 'r')
    except:
        print("workspace.txt does not exist!")
        return
    w_list = ast.literal_eval(fr.read())
    for i in w_list:
        try:
            subprocess.Popen(w_list[i])
            print(i, "opened successfully!")
        except:
            print(i, "can't be opened!")
    fr.close()
    the_voice.say_and_print("Success!")
def intro():
    txt = "Hello,\nI am a personal assistant for your desktop."
    the_voice.say_and_print(txt)
    txt = "I was developed by:"
    the_voice.say_and_print(txt)
    for i in Assistant.creators:
        the_voice.say_and_print(i)
    txt = "I am your assistant, so you can call me whatever you want to."
    the_voice.say_and_print(txt)
    features()
def add_contact(name, key):
    decrypt('data_files/phone_book.txt', key)
    with open('data_files/phone_book.txt', mode='a',
              encoding='utf-8') as phone:
        print(
            "Enter whatsapp number along with country code(eg.+91 for india): "
        )
        the_voice.say("Enter whatsapp number along with country code")
        while True:
            number = input(">>>")
            if '+' not in number:
                print("Invalid number(Enter country code also)\nTry again")
                the_voice.say(
                    "Invalid number Enter country code also\n Try again")
            else:
                break
        L = [" \n", name, " ", number]
        phone.writelines(L)
        the_voice.say_and_print(
            "Do you want to send a message to this number, yes or no?")
        while True:
            flag2 = the_voice.listening()
            try:
                flag2 = flag2.lower()
                if flag2 == 'yes':
                    break
                elif flag2 == 'no':
                    encrypt('data_files/phone_book.txt', key)
                    return
                else:
                    the_voice.say_and_print("Please say Yes or No!")
            except:
                print("Sorry, didn't get what you said, please try again")
        RECEIVER = number
        print("Sending to:", RECEIVER)
        the_voice.say("Sending to " + RECEIVER)
        send(RECEIVER, key)
    encrypt('data_files/phone_book.txt', key)
Beispiel #9
0
def score():
    try:
        print('=====================')
        the_voice.say_and_print('Live Cricket Matches:')
        url = "http://static.cricinfo.com/rss/livescores.xml"
        r = requests.get(url)
        soup = BeautifulSoup(r.text, 'lxml')
        i = 1
        for item in soup.findAll('item'):
            temp = item.find('description').text
            print(str(i) + '. ' + temp)
            temp = temp.replace(" v ", " versus ")
            temp = temp.replace(" *", "")
            temp = temp.replace("/", " for ")
            temp = temp.replace("T20", "T 20")
            the_voice.say(temp)
            i = i + 1

        links = []
        for link in soup.findAll('item'):
            links.append(link.find('guid').text)
    except Exception as e:
        print(e)
        print("* Error in showing cricket score *")
Beispiel #10
0
def start():
    the_voice.say_and_print("Say what you want to calculate?")
    ex = the_voice.listening()
    while True:
        try:
            ex.lower()
        except:
            print("Say the expression or \"CANCEL\" to cancel")
            ex = the_voice.listening()
            continue
        if ex == "cancel":
            the_voice.say_and_print("okay!")
            return
        result = (calc(ex))
        if result is not None:
            the_voice.say_and_print(str(result))
        print("Say the expression or \"CANCEL\" to cancel")
        ex = the_voice.listening()
Beispiel #11
0
def collect_user_data():
    the_voice.say_and_print("What's your name?")
    nm = input(">>>")
    user.set_name(nm)

    the_voice.say_and_print("What's your date of birth?")
    print("(In YYYY/MM/DD format)")
    dt = input(">>>")
    try:
        dt = dt.split("/")
        if len(dt[0]) == 4 and len(dt[1]) <= 2 and len(dt[2]) <= 2:
            yr = int(dt[0])
            mon = int(dt[1])
            date = int(dt[2])
            temp = datetime.datetime(yr, mon, date)
            user.set_dob(temp)
    except:
        print("Not a valid date format!")

    the_voice.say_and_print("What's your gender?")
    gen = input(">>>")
    user.set_gender(gen)

    the_voice.say_and_print("What's your email?")
    em = input(">>>")
    user.set_email(em)

    the_voice.say_and_print("What should I call you?")
    print("Enter nick name")
    nicknm = input(">>>")
    user.set_nicknm(nicknm)
    fw = open("data_files/user_data.txt", "w")
    fw2 = open("data_files/" + user.first_nm.lower() + "_data.txt", "w")
    fw.write(str(user.__dict__))
    fw2.write(str(user.__dict__))
    fw.close()
    fw2.close()
    the_voice.say_and_print("User data saved successfully!")
    the_voice.say_and_print("Hello " + user.nicknm + ", what are my orders?")
Beispiel #12
0
def change_user(fnm):
    fnm = fnm.lower()
    if user.first_nm.lower() == fnm:
        the_voice.say_and_print("That is already the current user!")
        return
    while True:
        try:
            fr = open("data_files/" + fnm + "_data.txt", "r")
            break
        except:
            print("data_files/" + fnm + "_data.txt does not exists!")
            the_voice.say_and_print("No such user found!")
            the_voice.say_and_print(
                "Please type the first name or \"CANCEL\" to cancel")
            fnm = input(">>>")
            fnm = fnm.lower()
            if fnm == "cancel":
                return
            if user.first_nm.lower() == fnm:
                the_voice.say_and_print("That is already the current user!")
                return
    fw = open("data_files/user_data.txt", "w")
    newdata = fr.read()
    fw.write(newdata)
    fr.close()
    fw.close()
    set_user_data()
    the_voice.say_and_print("User updated successfully!")
    the_voice.say_and_print("Hello " + user.nicknm + ", what are my orders?")
Beispiel #13
0
def start():
    encryptor_decryptor.safe_key_generator()
    key = encryptor_decryptor.load_key()
    while 1:
        while 1:
            the_voice.say_and_print("Name of user whose inbox is to be opened")
            name = the_voice.listening()
            decrypt('data_files/sender.txt', key)
            with open('data_files/sender.txt', mode='r',
                      encoding='utf-8') as open_sender:
                flag = 0
                for senders in open_sender:
                    if name.lower() == senders.split()[0].lower().rstrip():
                        BY = senders.split()[1].lower().rstrip()
                        flag = 1
                        read(BY, key)
                        break
                encrypt('data_files/sender.txt', key)
                if flag == 0:
                    the_voice.say_and_print(
                        "This person is not in your user's list")
                    while 1:
                        the_voice.say_and_print(
                            "Add this person in list yes or no ?")

                        flag = the_voice.listening()
                        b = type("h")
                        if type(flag) == b:
                            if flag.lower() == 'yes':
                                decrypt('data_files/sender.txt', key)
                                with open('data_files/sender.txt',
                                          mode='a',
                                          encoding='utf-8') as sender:
                                    while 1:
                                        the_voice.say_and_print(
                                            "Tell user's email address")
                                        BY = the_voice.listening()
                                        if '@gmail.com' in BY or '@juitsolan.in' in BY:
                                            L = [" \n", name, " ", BY, " "]
                                            sender.writelines(L)
                                            the_voice.say_and_print(
                                                "Tell password: "******"Continue with this user yes or no ?"
                                                )
                                                flag = "none"
                                                flag = the_voice.listening()
                                                if flag == 'yes':
                                                    read(BY, key)
                                                    break
                                                elif flag == 'no':
                                                    the_voice.say_and_print(
                                                        "Okay")
                                                    break
                                                else:
                                                    the_voice.say_and_print(
                                                        "Try again")
                                            break
                                        else:
                                            the_voice.say_and_print(
                                                "Wrong gmail format")
                                            the_voice.say_and_print(
                                                "Try again")
                                encrypt('data_files/sender.txt', key)
                                break
                            elif flag.lower() == 'no':
                                break
                            else:
                                the_voice.say_and_print("Try again")
                        else:
                            the_voice.say_and_print("Try again")
            while 1:
                the_voice.say_and_print("Read again yes or no ?")
                flag = the_voice.listening()
                b = type("h")
                if type(flag) == b:
                    if flag.lower() == 'yes':
                        break
                    elif flag.lower() == 'no':
                        the_voice.say_and_print("See you again ")
                        return 1
                    else:
                        the_voice.say_and_print("Try again")
                else:
                    the_voice.say_and_print("Try again")
Beispiel #14
0
def send(BY, key):
    the_voice.say_and_print("Tell the name of receiver or \"CANCEL\" to cancel")
    name = the_voice.listening()
    while 1:
        try:
            name = name.lower()
            if name == "cancel":
                return
            break
        except:
            the_voice.say_and_print("Tell the name of receiver or \"CANCEL\" to cancel")
        name = the_voice.listening()

    decrypt('data_files/mycontacts.txt', key)
    with open('data_files/mycontacts.txt', mode='r', encoding='utf-8') as open_receiver:
        while 1:
            flag = 0
            for receiver in open_receiver:
                name2 = receiver.split()[0].lower().rstrip()
                if name == name2:
                    flag = 1
                    TO = receiver.split()[1].lower().rstrip()
                    TO = TO.rstrip()
            if flag == 0:
                the_voice.say_and_print("This person is not in your receiver's list!")
                the_voice.say_and_print("Add this person in list, yes or no?")
                the_voice.say_and_print("or say \"CANCEL\" to cancel")
                while 1:
                    flag = the_voice.listening()
                    while 1:
                        try:
                            flag = flag.lower()
                            if flag == "cancel":
                                encrypt('data_files/mycontacts.txt', key)
                                return
                            break
                        except:
                            print("Say yes or no, or say \"CANCEL\" to cancel")
                        flag = the_voice.listening()
                    if flag.lower() == 'yes':
                        decrypt('data_files/mycontacts.txt', key)
                        with open('data_files/mycontacts.txt', mode='a', encoding='utf-8') as receive:
                            while 1:
                                the_voice.say_and_print("Enter receiver's email address or \"CANCEL\" to cancel")
                                TO = input(">>>")
                                if type(TO) != type("abc"):
                                    print("Email address can't be empty!")
                                    print("Enter email or \"CANCEL\" to cancel")
                                    continue
                                if "@" in TO and "." in TO:
                                    L = [" \n", name, " ", TO]
                                    receive.writelines(L)
                                    break
                                elif TO.lower() == 'cancel':
                                    encrypt('data_files/mycontacts.txt', key)
                                    return
                                else:
                                    the_voice.say_and_print("Wrong email format!")
                                    the_voice.say_and_print("try again...")
                                    continue
                        encrypt('data_files/mycontacts.txt', key)
                        break
                    elif flag.lower() == 'no':
                        print("Say the name of receiver again or \"CANCEL\" to cancel")
                        name = the_voice.listening()
                        while 1:
                            try:
                                name = name.lower()
                                if name == "cancel":
                                    encrypt('data_files/mycontacts.txt', key)
                                    return
                                break
                            except:
                                print("Tell the name of receiver again or \"CANCEL\" to cancel")
                            name = the_voice.listening()
                        break
                    else:
                        print("Say \"YES\",\"NO\" or \"CANCEL\", try again")
                        continue
            else:
                break
    encrypt('data_files/mycontacts.txt', key)

    the_voice.say_and_print("connecting to host...")
    # s.starttls()  # Extending the transport layer security
    # print("information encrypted...")
    # decrypt('data_files/sender.txt', key)
    # with open('data_files/sender.txt', mode='r', encoding='utf-8') as f:
    #     for item in f:
    #         if item.split()[1].lower().rstrip() == BY:
    #             flag = 1
    #             temp = item
    #     if flag == 1:
    #         try:
    #             s.login(BY, temp.split()[2].lower().rstrip())
    #             print("login successful...\n")
    #             encrypt('data_files/sender.txt', key)
    #         except Exception as e:
    #             print("!! Something is wrong with sender credentials or other app access setting !!")
    #             print(e)
    #             return 1
    #     else:
    #         the_voice.say_and_print("Data is not written in file!!")
    #         return 1
    the_voice.say_and_print("What is the subject or say \"CANCEL\" to cancel")
    SUBJECT = the_voice.listening()
    while 1:
        try:
            SUBJECT = SUBJECT.lower()
            if SUBJECT == "cancel":
                return
            break
        except:
            print("Tell the name of receiver again or \"CANCEL\" to cancel")
        SUBJECT = the_voice.listening()

    while 1:
        the_voice.say_and_print("What is the message or say \"CANCEL\" to cancel")
        body = the_voice.listening()
        while 1:
            try:
                if body.lower() == "cancel":
                    return
                break
            except:
                print("Please tell the message or say \"CANCEL\" to cancel")
            body = the_voice.listening()

        print(body)
        the_voice.say_and_print("Is this correct yes or no?")
        while 1:
            is_it = the_voice.listening()
            while 1:
                try:
                    is_it = is_it.lower()
                    if is_it == "cancel":
                        return
                    break
                except:
                    print("Please say yes or no? Or say \"CANCEL\" to cancel")
                is_it = the_voice.listening()
            if is_it.lower() == "no":
                break
            elif is_it.lower() == "yes":
                msg = MIMEMultipart()
                msg['From'] = BY
                msg['To'] = TO
                msg['Subject'] = SUBJECT
                msg.attach(MIMEText(body, 'plain'))
                try:
                    s.send_message(msg)
                except Exception as e:
                    print("Failed to send!")
                    print(e)
                    return
                the_voice.say_and_print("Message sent successfully!")
                del msg
                s.quit()
                return
            else:
                the_voice.say_and_print("just say 'yes', 'no' or 'cancel'!")
                continue
Beispiel #15
0
def start(cmd):
    if "find meaning" in cmd or ("tell" in cmd and "meaning" in cmd) or ("find" in cmd and "meaning" in cmd):
        the_voice.say_and_print("Say the word to get meaning")
        a = the_voice.listening()
        if a is None:
            print("Sorry, didn't get you!")
            print("Please say the name of file to search, or \"CANCEL\" to cancel")
            while a is not None:
                a = the_voice.listening()
                a = a.lower()
                if a == "cancel":
                    return 1
        a = a.lower()
        the_voice.say_and_print("Finding meaning...")
        tell_meaning.meaning(a)
        return 1

    elif "search google" in cmd or "find on google" in cmd or ("search" in cmd and "net" in cmd) or (
            "search" in cmd and "google" in cmd):
        the_voice.say_and_print("What do you want to search?")
        a = the_voice.listening()
        if a is None:
            print("Sorry, didn't get you!")
            print("Please say the name of file to search, or \"CANCEL\" to cancel")
            while a is not None:
                a = the_voice.listening()
                a = a.lower()
                if a == "cancel":
                    return 1
        a = a.lower()
        the_voice.say_and_print("Searching...")
        google_search.search(a)
        return 1

    elif "open site" in cmd or ("open" in cmd and "site" in cmd):
        the_voice.say_and_print("which site do you want to open?")
        a = the_voice.listening()
        if a is None:
            print("Sorry, didn't get you!")
            print("Please say the name of file to search, or \"CANCEL\" to cancel")
            while a is not None:
                a = the_voice.listening()
                a = a.lower()
                if a == "cancel":
                    return 1
        a = a.lower()
        the_voice.say_and_print("Opening Site...")
        frequent_site.site(a)
        return 1
    elif "set reminder" in cmd or ("set" in cmd and "reminder" in cmd):
        the_voice.say_and_print("What shall I remind you about?")
        a = the_voice.listening()
        if a is None:
            print("Sorry, didn't get you!")
            print("Please say the name of file to search, or \"CANCEL\" to cancel")
            while a is not None:
                a = the_voice.listening()
                a = a.lower()
                if a == "cancel":
                    return 1
        a = a.lower()
        the_voice.say_and_print("Setting reminder...")
        the_voice.say_and_print("In how many seconds you want to be reminded?")
        while True:
            temp = the_voice.listening()
            try:
                b = int(temp)
                break
            except:
                if temp.lower() == "cancel":
                    return 1
                the_voice.say_and_print("Please tell after how many seconds you want to be reminded, or say \"CANCEL\" to cancel")
        set_reminder.task(a, b)
        return 1

    elif "movies nearby" in cmd or "search movies" in cmd or ("movies" in cmd and "nearby" in cmd) or (
            "search" in cmd and "movies" in cmd):
        the_voice.say_and_print("Showing Movies Near by...")
        movies_nearby.movies("movies nearby")
        return 1

    elif "plan travel" in cmd or ("plan" in cmd and "travel" in cmd) or ("book" in cmd and "hotel" in cmd) or (
            "book" in cmd and "flight" in cmd) or ("book" in cmd and "train" in cmd) or (
            "book" in cmd and "bus" in cmd):
        the_voice.say_and_print("Plan Your Travel")
        plan_travel.travel()
        return 1

    elif "latest updates" in cmd or ("latest" in cmd and "updates" in cmd) or ("tell" in cmd and "news" in cmd):
        the_voice.say_and_print("Showing Latest Feeds...")
        news_update.news()
        return 1

    elif "cricket score" in cmd or ("cricket" in cmd and "score" in cmd) or ("live" in cmd and "cricket" in cmd):
        the_voice.say_and_print("Showing Cricket Score...")
        cricket_score.score()
        return 1

    return 0
def start():
    encryptor_decryptor.safe_key_generator()
    key = encryptor_decryptor.load_key()
    while 1:
        the_voice.say_and_print("Who is the receiver?")
        while True:
            name = the_voice.listening()
            try:
                name = name.lower()
                if name == "cancel":
                    return
                break
            except:
                print(
                    "Sorry didn't get you, please tell the name or \"CANCEL\" to cancel"
                )
        print("Receiver:", name)
        decrypt('data_files/phone_book.txt', key)
        with open('data_files/phone_book.txt', mode='r',
                  encoding='utf-8') as contacts_file:
            flag = 0
            for contacts in contacts_file:
                name2 = contacts.split()[0]
                name2 = name2.lower()
                if name2 == name:
                    flag = 1
                    RECEIVER = contacts.split()[1]
                    RECEIVER = RECEIVER.rstrip()
                    print("sending to: ", RECEIVER)
                    encrypt('data_files/phone_book.txt', key)
                    send(RECEIVER, key)
        if flag == 0:
            the_voice.say_and_print("Given name is not in your contact list!")
            while 1:
                the_voice.say_and_print(
                    "Enter this in contact list, yes or no?")
                flag = the_voice.listening()
                try:
                    flag = flag.lower()
                    if flag == 'yes':
                        add_contact(name, key)
                        break
                    elif flag == 'no':
                        break
                    else:
                        the_voice.say_and_print("Please say Yes or No!")
                except:
                    print("Sorry, didn't get what you said, please try again")

            the_voice.say_and_print("Send again, yes or no?")

        while True:
            flag3 = the_voice.listening()
            try:
                flag3 = flag3.lower()
                if flag3 == 'yes':
                    break
                elif flag3 == 'no':
                    return
                else:
                    the_voice.say_and_print("Please say Yes or No!")
            except:
                print("Sorry, didn't get what you said, please try again")
Beispiel #17
0
def update_sender():
    while 1:
        the_voice.say_and_print("Name the sender or say \"CANCEL\" to cancel")
        name = the_voice.listening()
        while 1:
            try:
                name = name.lower()
                if name == "cancel":
                    return
                break
            except:
                print("Name the sender or say \"CANCEL\" to cancel")
            name = the_voice.listening()

        decrypt('data_files/sender.txt', key)
        with open('data_files/sender.txt', mode='r', encoding='utf-8') as open_sender:
            flag = 0
            for senders in open_sender:
                if name.lower() == senders.split()[0].lower().rstrip():
                    flag = 1
                    BY = senders.split()[1].lower().rstrip()
                    print("Information encrypted!")
                    try:
                        s.login(BY, senders.split()[2].lower().rstrip())
                        the_voice.say_and_print("Login successful!")
                    except Exception as e:
                        print("Something is wrong with sender credentials or account access settings!")
                        print(e)
                        return 1
                    send(BY, key)
                    break
            encrypt('data_files/sender.txt', key)
            if flag == 0:
                the_voice.say_and_print("This person is not in your sender's list!")
                while 1:
                    the_voice.say_and_print("Add this person in senders list, yes or no? Or say \"CANCEL\" to cancel.")
                    flag = the_voice.listening()
                    if type(flag) == type("abc"):
                        if flag.lower() == 'yes':
                            decrypt('data_files/sender.txt', key)
                            with open('data_files/sender.txt', mode='a', encoding='utf-8') as sender:
                                while 1:
                                    the_voice.say_and_print("Enter sender's email address or \"CANCEL\" to cancel.")
                                    while 1:
                                        BY = input(">>>")
                                        try:
                                            BY = BY.lower()
                                            if BY == "cancel":
                                                encrypt('data_files/sender.txt', key)
                                                return
                                            break
                                        except:
                                            print("Sender's email address can't be empty!")
                                            print("Enter email or \"CANCEL\" to cancel.")
                                    if '@' in BY and '.' in BY:
                                        the_voice.say_and_print("Enter password or \"CANCEL\" to cancel.")
                                        PassWord = input(">>>")
                                        while 1:
                                            try:
                                                PassWord = PassWord.lower()
                                                if PassWord == "cancel":
                                                    encrypt('data_files/sender.txt', key)
                                                    return
                                                break
                                            except:
                                                the_voice.say_and_print("Enter password or \"CANCEL\" to cancel.")
                                            PassWord = input(">>>")
                                        L = [" \n", name, " ", BY, " ", PassWord]
                                        sender.writelines(L)

                                        the_voice.say_and_print("Sender is added successfully")
                                        send(BY, key)
                                        while 1:
                                            the_voice.say_and_print(
                                                "Continue messaging from this sender, yes or no? Or say \"CANCEL\" to cancel.")
                                            flag2 = the_voice.listening()
                                            while 1:
                                                try:
                                                    flag2 = flag2.lower()
                                                    if flag2 == "cancel":
                                                        encrypt('data_files/sender.txt', key)
                                                        return
                                                    break
                                                except:
                                                    print("Say yes , no or \"CANCEL\" to cancel.")
                                                flag2 = the_voice.listening()
                                            if flag2 == 'yes':
                                                the_voice.say_and_print("Okay!")
                                                send(BY, key)
                                            elif flag2 == 'no':
                                                the_voice.say_and_print("Okay!")
                                                break
                                            else:
                                                the_voice.say_and_print("Try again!")
                                                continue
                                        break
                                    else:
                                        the_voice.say_and_print("Wrong gmail format!")
                                        the_voice.say_and_print("try again...")
                                        continue
                            encrypt('data_files/sender.txt', key)
                            break
                        elif flag.lower() == 'no':
                            break
                        else:
                            the_voice.say_and_print("Wrong input try again")
                    else:
                        the_voice.say_and_print("Try again...")
                        continue
def features():
    txt = "\nI can perform various tasks such as:"
    the_voice.say_and_print(txt)
    for i in Assistant.commands:
        txt = "say " + i + " " + Assistant.commands[i]
        the_voice.say_and_print(txt)
Beispiel #19
0
def start():
    while 1:
        the_voice.say_and_print("Use default sender,\"python\" ? say yes, no, or \"CANCEL\" to cancel")
        use_it = the_voice.listening()
        while 1:
            try:
                use_it = use_it.lower()
                if use_it == "cancel":
                    return
                break
            except:
                print("Say yes , no, or \"CANCEL\" to cancel")
            use_it = the_voice.listening()
        if use_it == "yes":
            # using default sender python
            decrypt('data_files/sender.txt', key)
            with open('data_files/sender.txt', mode='r', encoding='utf-8') as open_sender:
                for senders in open_sender:
                    if "python" == senders.split()[0].lower().rstrip():
                        BY = senders.split()[1].lower().rstrip()

                        try:
                            s.login(BY, senders.split()[2].lower().rstrip())
                            the_voice.say_and_print("Login successful!")
                        except Exception as e:
                            print("Something is wrong with sender credentials or account access settings!")
                            print(e)
                            encrypt('data_files/sender.txt', key)
                            return
                        send(BY, key)
                    else:
                        the_voice.say_and_print("Default user data destroyed!")
                        the_voice.say_and_print("Enter new user data")
                        update_sender()
            encrypt('data_files/sender.txt', key)
        elif use_it == "cancel":
            return
        elif use_it == "no":
            the_voice.say_and_print("Choose another sender...")
            update_sender()
        else:
            the_voice.say_and_print("Invalid input")
            continue

        while 1:
            the_voice.say_and_print("Send again, yes or no ")
            flag = the_voice.listening()
            if type(flag) == type("abc"):
                if flag == 'no':
                    encrypt('data_files/mycontacts.txt', key)
                    encrypt('data_files/sender.txt', key)
                    return
                elif flag == 'yes':
                    break
                else:
                    print("Say yes or no?")
            else:
                print("Say yes or no?")
Beispiel #20
0
def edit_user_data():
    try:
        fr = open("data_files/user_data.txt", "r")
    except:
        print("user_data.txt not found!")
        return
    data = fr.read()
    try:
        data = eval(data)
        ex_nm = data['name']
        ex_nicknm = data['nicknm']
        ex_dob = data['dob']
        ex_gen = data['gender']
        ex_em = data['email']
        fr.close()
    except:
        print("data in data_files/user_data.txt is corrupted")
        fr.close()
        return

    print("Current Details:")
    print("Name:", data['name'], "\nNickname:", data['nicknm'],
          "\nDate of birth:", data['dob'], "\nGender:", data['gender'],
          "\nEmail:", data['email'], "\nAge:", data['age'])
    print("What's your name? (type \"Default\" for using existing value)")
    while True:
        nm = input(">>>")
        if nm is not None and nm.lower() != "default":
            user.set_name(nm)
            break
        elif nm is None:
            print("Name can not be empty!")
            print("Please enter your full name")
        else:
            nm = ex_nm
            user.set_name(nm)
            break
    print(
        "What's your date of birth? (type \"Default\" for using existing value)"
    )
    print("(In YYYY/MM/DD format)")
    while True:
        dt = input(">>>")
        if dt is not None and dt.lower() == "default":
            dt = ex_dob
            user.set_dob(dt)
            break
        try:
            dt = dt.split("/")
            if len(dt[0]) == 4 and len(dt[1]) <= 2 and len(dt[2]) <= 2:
                yr = int(dt[0])
                mon = int(dt[1])
                date = int(dt[2])
                temp = datetime.datetime(yr, mon, date)
                user.set_dob(temp)
                break
        except:
            print("Not a valid date format!")
            print("Please enter proper date of birth")

    print("What's your gender? (type \"Default\" for using existing value)")
    gen = input(">>>")
    if gen is not None and gen.lower() != "default":
        user.set_gender(gen)
    else:
        gen = ex_gen
        user.set_gender(gen)

    print("What's your email? (type \"Default\" for using existing value)")
    while True:
        em = input(">>>")
        if em is not None and em.lower() != "default":
            if "@" in em and "." in em:
                user.set_email(em)
                break
            else:
                print("Not a valid email address!")
                print("Enter proper email")
        else:
            em = ex_em
            user.set_email(em)
            break

    print(
        "What should I call you? (type \"Default\" for using existing value)")
    print("Enter nick name")
    nicknm = input(">>>")
    if nicknm is not None and nicknm.lower() != "default":
        user.set_nicknm(nicknm)
    else:
        nicknm = ex_nicknm
        user.set_nicknm(nicknm)

    fw = open("data_files/user_data.txt", "w")
    fw2 = open("data_files/" + user.first_nm.lower() + "_data.txt", "w")
    fw.write(str(user.__dict__))
    fw2.write(str(user.__dict__))
    fw.close()
    fw2.close()
    the_voice.say_and_print("User updated successfully!")
    the_voice.say_and_print("Hello " + user.nicknm + ", what are my orders?")
Beispiel #21
0
def read(BY, key):
    print("connecting to host....")
    try:
        imap = imaplib.IMAP4_SSL(host='imap.gmail.com', port=993)
    except Exception as e:
        print("Error connecting to host or port!")
        print(e)
        return
    print("information encrypted successfully ")
    try:
        imap.starttls()  # Extending the transport layer security
    except Exception as e:
        print("Transfer Layer Security is denied by server")
        pass
    decrypt('data_files/sender.txt', key)
    with open('data_files/sender.txt', mode='r', encoding='utf-8') as f:
        flag = 0
        for item in f:
            if item.split()[1].lower().rstrip() == BY:
                flag = 1
                temp = item
        if flag == 1:
            try:
                imap.login(BY, temp.split()[2].lower().rstrip())
                print("login successful")
                encrypt('data_files/sender.txt', key)
            except Exception as e:
                print(
                    "!! Something is wrong with sender credentials or other app access setting !!"
                )
                print(e)
                exit()
        else:
            print("Data is not written in file!!")
            exit()
    status, messages = imap.select(mailbox='inbox', readonly=True)
    messages = int(messages[0])
    the_voice.say_and_print("How many emails you want to read")
    N = int(the_voice.listening())

    for i in range(messages, messages - N, -1):
        # fetch the email message by ID
        res, msg = imap.fetch(
            message_set=str(i), message_parts="(RFC822)"
        )  # msg gets tuple of message envelope and content
        # print(msg)
        for response in msg:
            if isinstance(response, tuple):
                # parse a bytes email into a message object
                msg = email.message_from_bytes(response[1])  # Message parser
                # decode the email subject
                subject = decode_header(msg["Subject"])[0][
                    0]  # subject is a list of one tuple, first in tuple is our real subject
                if isinstance(subject, bytes):
                    # if it's a bytes, decode to str
                    subject = subject.decode()
                # email sender
                from_ = msg.get("From")
                print("Subject:", subject)
                print("From:", from_)
                # if the email message is multipart
                if msg.is_multipart():
                    # iterate over email parts
                    for part in msg.walk():
                        # extract content type of email
                        content_type = part.get_content_type()
                        # ***
                        content_disposition = str(
                            part.get("Content-Disposition"))
                        try:
                            # get the email body
                            body = part.get_payload(decode=True).decode()
                        except:
                            pass
                        if content_type == "text/plain" and "attachment" not in content_disposition:
                            # print text/plain emails and skip attachments
                            print(body)
                        elif "attachment" in content_disposition:
                            print("There are some attachments also")
                            # download attachment
                            filename = part.get_filename()  # **
                            if filename:
                                if not os.path.isdir('C:/File Attachments'):
                                    # make a folder for this email (named after the subject)
                                    os.mkdir('C:/File Attachments')
                                    print(
                                        " Attachment file is downloaded in C:/File Attachments"
                                    )
                                elif os.path.isdir('C:/File Attachments'):
                                    print(
                                        "The attachment file is already downloaded in C:/File Attachments"
                                    )
                                filepath = os.path.join(
                                    'C:/File Attachments/', filename)
                                # download attachment and save it
                                open(filepath,
                                     "wb").write(part.get_payload(decode=True))
                else:
                    # extract content type of email
                    content_type = msg.get_content_type()
                    # get the email body
                    body = msg.get_payload(decode=True).decode()
                    if content_type == "text/plain":
                        # print only text email parts
                        print(body)
                if content_type == "text/html":
                    print("There is html attachment")
                    # if it's HTML, create a new HTML file and open it in browser
                    if not os.path.isdir('C:/html_attach'):
                        # make a folder for this email (named after the subject)
                        try:
                            os.mkdir('C:/html_attach')
                        except Exception as e:
                            print(e)
                            pass
                    filename = f"{subject[:50]}.html"
                    filepath = os.path.join(
                        'C:/html_attach/',
                        filename)  # os.path.join(path, *paths)
                    # write the file
                    try:
                        open(filepath, "w").write(body)
                        # open in the chrome browser
                        chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
                        webbrowser.get(chrome_path).open(filepath)
                    except Exception as e:
                        print(e)
                        pass

                print("=" * 100)
    imap.close()
    imap.logout()
def send(RECEIVER, key):
    decrypt('data_files/sid-token.txt', key)
    with open('data_files/sid-token.txt', mode='r', encoding='utf-8') as id:
        for items in id:
            account_sid = items.split()[0]
            auth_token = items.split()[1]
    encrypt('data_files/sid-token.txt', key)

    client = Client(account_sid, auth_token)
    while True:
        the_voice.say_and_print("Enter message:")
        waap_message = the_voice.listening()
        while True:
            try:
                waap_message.lower()
                break
            except:
                print("Sorry didn't get you, please say again!")
            waap_message = the_voice.listening()
        print("Send?(yes/no)")
        the_voice.say("Send, yes or no")
        while 1:
            flag = the_voice.listening()
            try:
                flag = flag.lower()
                if flag == 'yes':
                    the_voice.say_and_print("Sending...")
                    break
                elif flag == 'no':
                    break
                else:
                    the_voice.say_and_print("Please say Yes or No!")
            except:
                print("Sorry didn't get what you said, please say again")
        if flag == 'yes':
            decrypt('data_files/sid-token.txt', key)
            with open('data_files/sid-token.txt', mode='r',
                      encoding='utf-8') as id:
                for items in id:
                    sandbox_number = items.split()[2]
            encrypt('data_files/sid-token.txt', key)
            try:
                message = client.messages.create(from_='whatsapp:' +
                                                 sandbox_number,
                                                 body=waap_message,
                                                 to='whatsapp:' + RECEIVER)
                print(message)
                the_voice.say_and_print("Message sent successfully!")
            except Exception as e:
                print(e)
                print("Message not send!")
            return
        elif flag == 'no':
            the_voice.say_and_print(
                "Do you wish to \"EDIT\" the message, or \"CANCEL\"")
            while True:
                ch = the_voice.listening()
                try:
                    ch = ch.lower()
                    if "edit" in ch:
                        break
                    elif "cancel" in ch:
                        return
                    else:
                        print("Please say \"EDIT\" or \"CANCEL\"")
                except:
                    print(
                        "Sorry, didn't get you please say \"EDIT\" or \"CANCEL\""
                    )