def __init__(self, contact_path, pass_path, email_recipient, subject, email_message, speak_type): self.email_recipient = email_recipient self.pass_path = pass_path self.contact_check = checkcontact(contact_path, email_recipient) with open( pass_path, 'r' ) as email_user_data: # open pass.json to get email password and username data = load(email_user_data) # load json self.email_user = data['email_address'] # get email address self.email_pass = data['email_password'] # get email password if self.contact_check != 'None': with open(contact_path, 'r') as contact_data_list: # get contact data contact_data = load(contact_data_list) # parse contact data self.recipient_email = contact_data['contacts'][ self.contact_check]['email'] # get email address of recipient # message area marvin_name = ('Marvin <' + self.email_user + '>') msg = MIMEMultipart() # formatting msg['From'] = marvin_name msg['To'] = self.recipient_email # input recipient email msg['Subject'] = subject # input subject msg.attach(MIMEText(email_message, 'plain')) # add body self.message = msg.as_string() # format all text else: # recipient not in contacts speak( 'This user is not in our contacts use the "add contacts" command to add ' + email_recipient, speak_type) # user not found message raise Exception
def contactList(self): if not self.list_contact_data['contacts']: # if no contacts print('No contacts use the add contacts command to add some' ) # no contact message elif not self.list_contact_data: # missing file and data print( 'Fatal Error\nMissing data make sure that you ran setup.py before running this script' ) # missing file and data message else: # there are contacts and there was a file thread_list_contact = Thread( target=listofcontacts ) # thread arguments to print list while speaking because of slow speak times thread_list_contact.start( ) # start thread of lisofcontacts function speak('Opening contact list\n', self.speak_type) # speak
def scrapeYoutube(self): if self.go_no_go == 'go': speak('Opening first video for ' + self.search_query + ' on YouTube', self.speak_type) # saying what it will open for v in self.vids: #for loop for finding all videos that show up if self.is_absolute(v['href']) == True: pass else: tmp = 'https://www.youtube.com' + v[ 'href'] # create url to add to list with links from html self.videolist.append( tmp) # add the newly created url to list webopen(self.videolist[0], new=2) # open the url print('Done!') # finish message else: speak('No internet connection couldn\'t access')
def getVersion(): if checkConnection() == True: url = ( 'https://github.com/SavageCoder77/MARVIN_2.0/blob/master/marvin/json/marvin_version.txt' ) r = get(url) # request page page = r.text soup = bs(page, 'html.parser') # parse html vids = soup.findAll( 'td', attrs={ 'id': 'LC1', 'class': 'blob-code blob-code-inner js-file-line' } ) # search for class meter-value superPageFontColor in html from page version_marvin = vids[0].getText() print('Marvin Version ' + str(version_marvin)) return version_marvin else: speak('No internet connection couldn\'t access')
def scrapeRottentomatoes(self): if go_no_go == 'go': try: rt = self.soup.findAll( 'span', attrs={'class': 'meter-value superPageFontColor'} ) # search for class meter-value superPageFontColor in html from page if rt == []: raise Exception raiting = rt[0].getText() speak( 'Rotten Tomatoes gave ' + self.search_query + ' ' + raiting, self.speak_type) people_score = self.soup.findAll('span', attrs={ 'class': 'superPageFontColor', 'style': 'vertical-align:top' }) score = people_score[0].getText() want_or_like = self.soup.findAll( 'div', attrs={ 'class': 'smaller bold hidden-xs superPageFontColor' }) like_or_want = want_or_like[0].getText() if like_or_want == 'liked it': speak( '\n' + score + ' of people liked ' + self.search_query, self.speak_type) elif like_or_want == 'want to see': speak('\n' + score + ' want to see ' + self.search_query, self.speak_type) else: raise Exception except Exception as e: speak( '\nI ran into a problem\nThe name of the movie was probably input incorrectly', self.speak_type) print(e) else: speak('No internet connection couldn\'t access')
def dataTaco(self): try: instructions = self.requested_taco.json()['recipe'] print('\n\nInstructions:\n' + instructions, file=open(self.taco_txt + '.txt', 'a')) except: print('\n\nInstructions:\nNo recipe for this section', file=open(self.taco_txt + '.txt', 'a')) if self.requested_taco.json()['shell_url'] is not None: shell_instructions = self.requested_taco.json()['shell']['recipe'] print('\n\nShell Instructions:\n' + shell_instructions, file=open(self.taco_txt + '.txt', 'a')) if self.requested_taco.json()['base_layer_url'] is not None: base_layer_instructions = self.requested_taco.json( )['base_layer']['recipe'] print('\n\nBase Layer Instructions:\n' + base_layer_instructions, file=open(self.taco_txt + '.txt', 'a')) if self.requested_taco.json()['seasoning_url'] is not None: season_instructions = self.requested_taco.json( )['seasoning']['recipe'] print('\n\nSeasoning Instructions:\n' + season_instructions, file=open(self.taco_txt + '.txt', 'a')) if self.requested_taco.json()['condiment_url'] is not None: condiment_instructions = self.requested_taco.json( )['condiment']['recipe'] print('\n\nCondiment Instructions:\n' + condiment_instructions, file=open(self.taco_txt + '.txt', 'a')) if self.requested_taco.json()['mixin_url'] is not None: mixin_instructions = self.requested_taco.json()['mixin']['recipe'] print('\n\nMixin Instructions:\n' + mixin_instructions, file=open(self.taco_txt + '.txt', 'a')) print('Full Recipe put into file called ' + self.taco_txt) speak('Opening the full taco recipe for you', self.speak_type)
def IMDb(self): if go_no_go == 'go': try: pg_up = self.soup.findAll('li', attrs={'class': 'meta-row clearfix'}) if pg_up == []: raise Exception up_pg = pg_up[0].getText() speak('\n' + self.search_query + ' got a IMDb' + up_pg, self.speak_type) except Exception as e: speak( '\nI ran into a problem\nThe name of the movie was probably input incorrectly', self.speak_type) else: speak('No internet connection couldn\'t access')
def scrapeDefinition(self): if go_no_go == 'go': try: define_find_type = self.soup.findAll( 'span', attrs={'class': 'luna-pos'}) define_find = self.soup.findAll( 'span', attrs={'class': 'css-9sn2pa e10vl5dg6'}) if define_find == []: raise Exception if define_find_type == []: raise Exception definition_type = define_find_type[0].getText() definition = define_find[0].getText() definition_type_corrected = self.removeComma(definition_type) speak( self.search_query + ' is a ' + definition_type_corrected + '\nThe definition is: ' + definition, self.speak_type) except Exception as e: speak( '\nI ran into a problem\nThe name of the word was probably input incorrectly', self.speak_type) print(e) else: speak('No internet connection couldn\'t access')
def ADMIN(contact_path, pass_path, speak_type): # ADMIN MENU bob = True while True: # loop for MENU so you don't have to keep reopening it try: print( '\nOnly use ADMIN acount for administrative tasks' ) # message to remind you can't use marvins command without a real user print( '\n######## ADMIN MENU ########\n\n1. Create New User 2. Delete a User\n3. Update Marvin 4. Marvin APPS\n5. Voice Settings 6. Leave ADMIN Menu\n7. Exit program' ) # show options ADMIN_input = input('>') # prompt for input if ADMIN_input == '1' or 'user' in ADMIN_input.lower( ): # check if user wants to create a user with open(pass_path, 'r') as login_data: # open user info new_user_data = load(login_data) # parse user info search_login = new_user_data[ 'logins'] # put users into variable print('Showing all Users') # print user printing user message for x in search_login: # loop for all users (x) # print all users print( 'You will choose a username and password for the new user\nType a User' ) # prompt for new usr and pass new_user = input('>') # type user if new_user in search_login: # check if user exists print('This user exists already') # user exists message elif 'quit' == new_user.lower() or 'exit' == new_user.lower( ) or 'cancel' == new_user.lower(): raise ValueError # check message for cancel else: # user doesn't exist while True: # loop until password over 5 characters print( '\nType a password for the new user thats over 5 characters' ) # message that pass have to be over 5 length new_user_pass = input('>') # input for new user pass if 'quit' == new_user_pass.lower( ) or 'exit' == new_user_pass.lower( ) or 'cancel' == new_user_pass.lower(): raise ValueError # check message for cancel elif len(new_user_pass ) <= 5: # if new password under 5 characters print('Make your password over 5 characters please' ) # more characters message else: # password over 5 characters break # break loop while True: # loop until correct passward print( '\nType your ADMIN password again to confirm this action' ) # ask for admin password login_pass = getpass('>') # input password login_pass2 = sha512( login_pass.encode('utf-8') + 'NQZVA').hexdigest( ) # hash password to match if in file if login_pass2 == new_user_data['logins']['ADMIN'][ 'pass']: # check if password matches break # leave loop elif 'quit' == login_pass2.lower( ) or 'exit' == login_pass2.lower( ) or 'cancel' == login_pass2.lower(): raise ValueError # check message for cancel else: # password doesn't match print('Incorect Credentials' ) # wrong password message i = i + 1 # add tries if i >= 5: # if over 5 tries exit() new_login = encode(new_user, 'rot13') # encode user name new_user_pass_encrypted = sha512( new_user_pass.encode('utf-8') + new_login.encode('utf-8')).hexdigest() # hash password print('Creating User') # print creating messsage with open(pass_path, 'w') as outfile: # open file to add changes new_user_data['logins'][new_user] = { "pass": new_user_pass_encrypted } # new user data dump(new_user_data, outfile) # add new user data print('New user created') # new user added messgae elif ADMIN_input == '2' or 'delete' in ADMIN_input.lower( ): # check if user wants to delete a user with open(pass_path, 'r' ) as login_data: # open file to find exisiting users new_user_data = load(login_data) # parse data search_login = new_user_data['logins'] # get all users print('Showing all Users') # showing users message for x in search_login: # loop until all users printed print(x) # print all users print('\nWhat user do you want to delete' ) # ask which user to delete del_user = input('>') # input for user to delete if del_user == 'ADMIN': # if input user is ADMIN print('Can\'t delete this user') # can't delete message elif 'quit' == del_user.lower() or 'exit' == del_user.lower( ) or 'cancel' == del_user.lower(): raise ValueError # check message for cancel elif del_user in search_login: # check if user exists while True: # loop until correct passward print( '\nType your ADMIN password again to confirm this action' ) # ask for admin password login_pass = getpass('>') # input password login_pass2 = sha512( login_pass.encode('utf-8') + 'NQZVA').hexdigest( ) # hash password to match if in file if login_pass2 == new_user_data['logins']['ADMIN'][ 'pass']: # check if password matches break # leave loop elif 'quit' == login_pass2.lower( ) or 'exit' == login_pass2.lower( ) or 'cancel' == login_pass2.lower(): raise ValueError # check message for cancel else: # password doesn't match print('Incorect Credentials' ) # wrong password message i = i + 1 # add tries if i >= 5: # if over 5 tries exit() del new_user_data['logins'][del_user] # del user and data with open(pass_path, 'w') as outfile: # open file dump(new_user_data, outfile) # add updated file else: # no user found print('This User doesn\'t exist') # no user found message elif ADMIN_input == '3' or 'update' in ADMIN_input.lower( ): # check if user want to update print('Checking for Update') # checking message with open('Os.json', 'r' ) as marvin_v: # open .Os.json to see marvin version marvin_ver = load(marvin_v) # parse data marvin_version = marvin_ver[ 'Marvin_Release'] # get local marvin version online_marvin_version = getVersion( ) # get online marvin version if str(marvin_version) != str( online_marvin_version): # if they don't match print('Update found') # found message system('git pull') # pull from github print( 'You will now have to reopen Marvin to make sure the changes went through' ) # restart message with open( 'Os.json', 'w' ) as outfile: # open .Os.json to change marvin version marvin_ver[ 'Marvin_Release'] = online_marvin_version # change marvin version dump(marvin_ver, outfile) # add new version number exit() else: # versions match print('No update found\n##############\nYou are up to date' ) # versions match message elif ADMIN_input == '4' or 'app' in ADMIN_input: print('\nshowing apps:\n') with open('Os.json', 'r' ) as marvin_a: # open .Os.json to see marvin version marvin_apps = load(marvin_a) # parse data print('IOS app : ' + marvin_apps['apps']['IOS']) print('\nWould you like to enable any apps?') app_input = input('>').lower() if app_input == 'yes' or 'y' in app_input: print('\nWhich app would you like to activate') app_active = input('>').lower() if app_active == 'ios' or app_active == 'apple': print('Type this into app for ip ' + get_ip()) elif 'quit' == app_active.lower( ) or 'exit' == app_active.lower( ) or 'cancel' == app_active.lower(): raise ValueError # check message for cancel elif 'quit' == app_input.lower() or 'exit' == app_input.lower( ) or 'cancel' == app_input.lower(): raise ValueError # check message for cancel else: print('Would you like to deactivate an app?') deactivate_input = input('>').lower() if 'quit' == deactivate_input.lower( ) or 'exit' == deactivate_input.lower( ) or 'cancel' == deactivate_input.lower(): raise ValueError # check message for cancel elif deactivate_input.lower( ) == 'y' or deactivate_input == 'y': pass elif ADMIN_input == '5' or 'voice' in ADMIN_input: with open('Os.json', 'r') as voice_settings: voice_loaded = load(voice_settings) print('\nVoice currently set to ' + voice_loaded['voice']) if voice_loaded['voice'] == 'female': print('\nWould you like to change to a male voice?') voice = input('>') if 'y' in voice: print('Changing to male voice') speak('This is what I sound like now', 'male') print(voice_loaded['voice']) with open('Os.json', 'w') as outfile: var = voice_loaded['voice'] = 'male' dump(voice_loaded, outfile) else: print('\nWould you like to change to a female voice?') voice = input('>') if 'y' in voice: print('Changing to female voice') speak('This is what I sound like now', 'female') with open('Os.json', 'w') as outfile: var = voice_loaded['voice'] = 'female' dump(voice_loaded, outfile) elif ADMIN_input == '6' or 'exit' in ADMIN_input.lower( ) or 'leave' in ADMIN_input.lower() or 'quit' in ADMIN_input.lower( ): # check if user wants to leave Menu print('Exiting ADMIN MENU') # exit menu message break # break loop to leave ADMIN MENU elif ADMIN_input == '7': # if you want to exit print('Exiting program') # exit message bob = False # close program break except: pass if bob == False: exit()
def timer(self, delay): print('Timer Started') time.sleep(float(delay)) speak('Timer Done!', self.speak_type)
def timerLogic(self): time_for_timer = self.time_for.split(" ")[0] if time_for_timer.lower() == 'zero' or time_for_timer == '0': self.bob = 0 speak('You can\'t have a timer for 0 time') if self.bob >= 1: time_unit = marvin.essentials.splitJoin(self.time_for, 1) if time_unit == '': time_unit = 'minutes' try: bob = float(time_for_timer) self.time_for_timer = float(time_for_timer) except ValueError: self.time_for_timer = float( w2n.word_to_num(str(time_for_timer))) if 'min' in time_unit: abs_time = abs(float(self.time_for_timer)) seconds_in_minutes = abs_time * 60 self.timer(seconds_in_minutes) elif 'sec' in time_unit: abs_time = abs(float(self.time_for_timer)) if abs_time >= 5.0: self.timer(float(abs_time)) else: speak( 'Any timer less than 5 seconds is to small count thousands', self.speak_type) elif 'hr' in time_unit: abs_time = abs(float(self.time_for_timer)) if abs_time <= 3: seconds_in_hour = abs_time * 3600 self.timer(seconds_in_hour) else: speak( 'Timer does not support reminders over 3 hours use a calander reminder for long reminders', self.speak_type) elif 'day' in time_unit: speak( 'Timer does not support days use a calander reminder for long reminders', self.speak_type) else: speak('I couldn\'t find the time unit you wanted to use', self.speak_type) else: speak('You need to input a number for the timer', self.speak_type)
raise marvin.commands.MarvinRelog # restart to login to not allow admins to use commands break # break loop if not admin else: # wrong password print( '\n#####################\nIncorrect Credentials\n#####################\n' ) # incorrect password message # MAIN command loop while True: # input type loop ''' core loop this is the part that will be looped to check user wants to keep using voice commands it will always ask the user the prompt below when the while loop goes back to the start part that will run when while loop resets ''' speak('\nChoose an option', speak_type) # ask for which type of input print( ' \nOPTIONS:\n1. voice commands\n2. typed commands\n3. standby\n4. quit\n ' ) # options for inputs beg_input = input(">").lower() # input for which option chosen if beg_input == '1' or 'voice' in beg_input: # voice commands try: # try to be able to restart loop while 1: # loop to repeat listening commands print('\nAwaiting commands') # prompt for command data = listen() #use listen function in commands.py marvin_command_data = marvin.commands.dataCommands( data.lower(), 1, pass_path, contact_path, correction_path, os_type, speak_type ) # check for command and lower what was just said
def dataCommands(command, type_of_input, pass_path, contact_path, correction_path, os_type, speak_type): bob = False # Website Commands # if 'open reddit' in command or 'open subreddit' in command: subreddit = splitJoin(command, 2) # function to split and rejoin command speak('Opening subreddit ' + subreddit + ' for you', speak_type) # saying the subreddit page webopen('https://www.reddit.com/r/' + subreddit, new=2) # open url in browser print('Done!') elif 'open google sheets' == command: speak('Opening Google Sheets for you', speak_type) # saying what it will open twitter webopen('https://docs.google.com/spreadsheets/u/0/', new=2) # open url in browser print('Done!') elif 'open google docs' == command: speak('Opening Google Docs for you', speak_type) # saying what it will open twitter webopen('https://docs.google.com/document/u/0/', new=2) # open url in browser print('Done!') elif 'google' in command: gsearch = splitJoin(command, 1) # function to split and rejoin command speak('Opening Google search for ' + gsearch, speak_type) # saying what it will open url = ('https://www.google.com/search?q=' + gsearch + '&rlz=1C5CHFA_enUS770US770&oq=' + gsearch + '&aqs=chrome..69i57.1173j0j8&sourceid=chrome&ie=UTF-8' ) # url with search webopen(url, new=2) # open url in browser print('Done!') elif 'open twitter' == command: speak('Opening Twitter for you', speak_type) # saying what it will open twitter webopen('https://twitter.com/', new=2) # open url in browser print('Done!') elif 'open facebook' == command: speak('Opening Facebook for you', speak_type) # saying what it will open twitter webopen('https://www.facebook.com/', new=2) # open url in browser print('Done!') elif 'open github' == command: speak('Opening Github for you', speak_type) # saying what it will open twitter webopen('https://github.com/', new=2) # open url in browser print('Done!') elif 'open stack overflow' == command: speak('Opening Stack Overflow for you', speak_type) # saying what it will open twitter webopen('https://stackoverflow.com/', new=2) # open url in browser print('Done!') elif 'where is' in command: location = splitJoin(command, 2) # function to split and rejoin command speak('Hold on, I will show you where ' + location + ' is.', speak_type) # saying the location heard url = ('https://www.google.nl/maps/place/' + location + '/&' ) # url with location webopen(url, new=2) # open url in browser print('Done!') elif 'amazon' in command: amazon = splitJoin(command, 1) # function to split and rejoin command speak('Searching amazon for ' + amazon, speak_type) # saying what it will look for url = ( 'https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=' + amazon) # url with amazon search webopen(url, new=2) # open in browser print('Done!') elif 'time in' in command: time_in = splitJoin(command, 1) # function to split and rejoin command speak('Showing time in ' + time_in, speak_type) # saying what its opening url = ('https://time.is/' + time_in ) # url to time.is with the location webopen(url, new=2) # open in browser print('Done!') # Marvin Webscrape Commands # elif 'rotten tomatoes' in command: TomatoeScrape = TomatoeScrape(speak_type, command, 1) TomatoeScrape.scrapeRottentomatoes() elif 'imdb' in command: if 'imdb rating' in command: num_type = 2 elif 'imdb' in command: num_type = 1 TomatoeScrape = TomatoeScrape(speak_type, command, num_type) TomatoeScrape.IMDb() elif 'youtube' in command: if 'search youtube' in command: num_type = 2 elif 'play in youtube' in commands: num_type = 3 elif 'youtube' in command: num_type = 1 Youtube_Scrape = YoutubeScrape(speak_type, command, num_type) Youtube_Scrape.scrapeYoutube() # function to scrape urls elif 'define' in command or 'what is the definition of' in command: if 'what is the definition of' in command: num_type = 5 elif 'define' in command: num_type = 1 Definition_Find = DefinitionFind(speak_type, command, num_type) Definition_Find.scrapeDefinition() # function to scrape urls # Marvin Api Commands # elif 'full random taco' == command: Api_Service = ApiService(speak_type) Api_Service.tacoFullRand() Api_Service.dataTaco() elif 'random taco' == command: Api_Service = ApiService(speak_type) Api_Service.tacoFullRand() Api_Service.dataTaco() # Marvin Function Commands # elif 'standby' in command: speak('Going on standby', speak_type) raise MarvinCommands # raise exeption so class passes and restarts loop elif command == 'exit' or command == 'quit' or command == 'leave' or command == 'close' or command == 'shutdown' or command == 'shut down': speak('Shutting down', speak_type) exit() # leave program elif command == 'relog' or command == 'logout': speak('logging out', speak_type) raise MarvinRelog elif command == 'ls' or command == 'dir': if os_type == 'Linux': system('ls') elif os_type == 'Darwin': system('ls') elif os_type == 'Windows': system('dir') # Sending based Commands elif command == 'contact list' or command == 'contacts': ContactService = marvin.contacts.ContactShow(contact_path, 0, speak_type) ContactService.contactList() elif command == 'delete contact' or command == 'remove contact': try: ContactService = marvin.contacts.ContactShow( contact_path, 1, speak_type) ContactService.contactList() print('input cancel to cancel delete contact') # cancel message speak('Who would you like to delete from your contacts?', speak_type) delete_contact = commandInput( type_of_input).lower() # function for listen or raw_input if 'quit' == delete_contact.lower( ) or 'exit' == delete_contact.lower( ) or 'cancel' == delete_contact.lower(): raise ValueError # check message for cancel with open(contact_path, 'r') as contact_del_list: del_contact_data = load(contact_del_list) if delete_contact.lower() not in del_contact_data['contacts']: print('User does not exist') raise ValueError del del_contact_data['contacts'][delete_contact] with open(contact_path, 'w') as outfile: dump(del_contact_data, outfile) speak(delete_contact + ' has been removed', speak_type) except Exception as e: print('Cancelling') elif command == 'add contact' or command == 'new contact': try: ContactService = marvin.contacts.ContactShow( contact_path, 1, speak_type) ContactService.contactList() print('input cancel to cancel add contact') # cancel message speak('Who would you like to add to you contacts?', speak_type) print('First name please') add_contact = commandInput( type_of_input) # function for listen or raw_input if 'quit' == add_contact.lower() or 'exit' == add_contact.lower( ) or 'cancel' == add_contact.lower(): raise ValueError # check message for cancel print('input cancel to cancel add contact') # cancel message speak('What is ' + add_contact + '\'s email?', speak_type) new_email = commandInput( type_of_input) # function for listen or raw_input if 'quit' == new_email.lower() or 'exit' == new_email.lower( ) or 'cancel' == new_email.lower(): raise ValueError # check message for cancel print('input cancel to cancel add contact') # cancel message speak( 'What is ' + add_contact + '\'s phone number? If you don\'t have it or you dont want to input respond with None', speak_type) new_phone_number = commandInput( type_of_input) # function for listen or raw_input if 'quit' == new_phone_number.lower( ) or 'exit' == new_phone_number.lower( ) or 'cancel' == new_phone_number.lower(): raise ValueError # check message for cancel speak( 'Does this contact have a nickname you like to add? If they don\'t have one type none', speak_type) nick = commandInput( type_of_input) # function for listen or raw_input nick_lower = nick.lower() if 'quit' == nick_lower or 'exit' == nick_lower or 'cancel' == nick_lower: raise ValueError # check message for cancel with open(contact_path, 'r') as contact_data: new_contact_data = load(contact_data) # read data add_contact_lowered = add_contact.lower() if 'none' != nick_lower: new_contact_data['nicks'][nick_lower] = { "real_name": add_contact_lowered } speak('Creating contact', speak_type) with open(contact_path, 'w') as outfile: new_contact_data['contacts'][add_contact_lowered] = { "email": new_email, "number": new_phone_number } # new data to add dump(new_contact_data, outfile) # add data print('Contact Created!') except Exception as e: print('Cancelling') elif command == 'send email': try: ContactService = marvin.contacts.ContactShow( contact_path, 'email', speak_type) ContactService.contactList() print('input cancel to cancel send email') # cancel message speak('Who would you like to send this email to?', speak_type) email_recipient = commandInput( type_of_input).lower() # function for listen or raw_input if 'quit' == email_recipient.lower( ) or 'exit' == email_recipient.lower( ) or 'cancel' == email_recipient.lower(): raise ValueError # check message for cancel print('input cancel to cancel send email') # cancel message speak('What is the subject of the email?', speak_type) email_subject = commandInput( type_of_input) # function for listen or raw_input if 'quit' == email_subject.lower( ) or 'exit' == email_subject.lower( ) or 'cancel' == email_subject.lower(): raise ValueError # check message for cancel print('input cancel to cancel send email') # cancel message speak( 'What is the message you would like to send to ' + email_recipient, speak_type) email_body = commandInput( type_of_input) # function for listen or raw_input if 'quit' == email_body.lower() or 'exit' == email_body.lower( ) or 'cancel' == email_body.lower(): raise ValueError # check message for cancel new_send_email = Email(contact_path, pass_path, email_recipient, email_subject, email_body, speak_type) Email_Service = EmailService() thread_email = Thread(target=Email_Service.sendemail, args=(new_send_email, )) thread_email.start() except Exception as e: print('Cancelling') # Misc Commands # elif command == 'what time is it' or command == 'current time': speak('The time is ' + datetime.now().strftime('%-I:%M %p'), speak_type) elif command == 'what is the date' or command == 'what\'s the date' or command == 'current date' or command == 'date today': speak('The date is ' + datetime.now().strftime('%A %B %-d %Y'), speak_type) elif "day of the week" in command or command == 'what day is it': speak(datetime.now().strftime('%A'), speak_type) elif command == 'week number': speak(datetime.now().strftime('%W'), speak_type) elif 'set a timer for' in command: time_for = splitJoin(command, 4) # function to split and rejoin command Timer_Service = TimerService(time_for, speak_type) thread_timer = Thread(target=Timer_Service.timerLogic) thread_timer.start() elif command == 'open calculator' or command == 'run calculator' or command == 'calculator': thread_calculator = Thread( target=openCalculator) # run calculator code from calculator.py print('Calculator Opened!') # open message thread_calculator.start( ) # start 2nd thread with calulator so you can run commands along with the calculator open elif command == 'open stopwatch' or command == 'run stopwatch' or command == 'stopwatch': thread_stopwatch = Thread( target=openStopwatch) # run calculator code from calculator.py print('Stopwatch Opened!') # open message thread_stopwatch.start( ) # start 2nd thread with calulator so you can run commands along with the calculator open # Help commands elif command == 'help': for c in command_list: print(c) # Chance commands elif command == 'dice' or command == 'what dice can I roll': speak('You can roll a \nd4, d6, d8, d10, d12, d20', speak_type) elif command == 'roll a die' or command == 'd6' or command == '6 sided dice' or command == 'roll a d6' or command == 'roll a 6 sided die': rand_roll = random.randint(1, 6) speak('You rolled a ' + str(rand_roll), speak_type) marvin.asciiart.d6Roll(rand_roll) elif command == 'flip a coin' or command == 'flip coin': rand_coin = random.randint(1, 2) if rand_coin == 1: speak('You flipped head', speak_type) rand_face = random.randint(1, 2) if rand_face == 1: marvin.asciiart.head1Coin() else: marvin.asciiart.head2Coin() else: speak('You flipped tails', speak_type) marvin.asciiart.tailCoin() # Marvin Interaction elif command == 'hello' or command == 'hi': speak('Hello!', speak_type) elif command == 'who are you': speak( 'I\'m Marvin a virtual assistant created by Rafael Cenzano to make everyday life better and easier', speak_type) else: with open(correction_path, 'r') as check_correction: correction_check = load(check_correction) if command in correction_check['corrections']: correct_term = correction_check['corrections'][command]['correct'] return correct_term else: bob = True if bob == False: return 'null' elif bob == True: auto_corrected_list = get_close_matches(command, command_list, 1) if auto_corrected_list != []: auto_corrected = auto_corrected_list[0] speak('Did you mean ' + auto_corrected + '?', speak_type) input_auto_correct = commandInput( type_of_input) # function for listen or raw_input if 'y' in input_auto_correct: split_autocorrected = auto_corrected.split( " ") # split find how many words there are length_auto_corrected = len(split_autocorrected) length_needed = length_auto_corrected split_command_for_data = command.split(" ")[length_needed:] if split_command_for_data != []: joined_command_data = (" ").join( split_command_for_data ) # joining anything that was split from after any unnecessary words return auto_corrected + ' ' + joined_command_data else: correction_check['corrections'][command] = { "correct": auto_corrected } # new data to add with open(correction_path, 'w') as outfile: dump(correction_check, outfile) return auto_corrected else: print('Command not found') return 'null' else: print('Command not found') return 'null' else: print('Error missing variable') raise MarvinRelog