def send_mail(): import smtplib smtpObj = smtplib.SMTP('smtp.gmail.com', 587) smtpObj.ehlo() smtpObj.starttls() sender_email = '*****@*****.**' sender_password = '******' smtpObj.login(sender_email, sender_password) receiver_email = [] formatting.line() n = input('Please enter total number of receivers: ') formatting.line() for i in range(int(n)): receiver_email.append( input('Enter email of receiver ' + str(i + 1) + ': ')) formatting.line() sub = prompt('Please tell subject.') body = prompt('Please tell your message') content = 'Subject:' + sub + '\n' + body formatting.head('Message') formatting.table_content('*', 'From', sender_email, 12, 58) formatting.table_content('*', 'To', str(receiver_email), 12, 58) formatting.table_content('*', 'Subject', sub, 12, 58) formatting.text_box(body) temp = 'y' temp = input('Are you sure to send mail?(Y/n): ') if (temp == 'y' or temp == 'Y'): for i in range(int(n)): smtpObj.sendmail(sender_email, receiver_email[i], content) print('Email sent successfully!') return else: print('Email not sent!') return
def prompt(mytext): formatting.text_box(mytext) voice.text_to_speech(mytext) var = voice.speech_to_text() if (voice.error_status(var)): prompt('Please try again') else: return var
def change_dir(): formatting.line() folder_name = input("Enter the name of directory: ") formatting.line() current_dir = os.getcwd() os.chdir(current_dir + "/" + folder_name) formatting.text_box(os.getcwd()) return
def today_date(): from datetime import date months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] today = date.today() day = str(today.day) month = months[int(today.month) - 1] year = str(today.year) formatting.text_box("Today's date is " + day + " " + month + " " + year) return
def execute(mytext): if (mytext.lower() == 'send email'): modules.send_mail() return elif (mytext.lower() == 'weather update'): modules.weather_update() return elif (mytext.lower() == 'list files'): modules.list_files() return elif (mytext.lower() == 'date'): modules.today_date() return elif (mytext.lower() == 'shutdown'): modules.shutdown_now() return elif (mytext.lower() == 'reboot'): modules.reboot_now() return elif (mytext.lower() == 'create file'): modules.create_file() return elif (mytext.lower() == 'file type'): modules.file_type() return elif (mytext.lower() == 'create user'): modules.create_user() return elif (mytext.lower() == 'delete user'): modules.delete_user() return elif (mytext.lower() == 'current directory'): modules.current_working_dir() return elif (mytext.lower() == 'create directory'): modules.create_dir() return elif (mytext.lower() == 'go back'): modules.back() return elif (mytext.lower() == 'change directory'): modules.change_dir() return elif (mytext.lower() == 'delete file'): modules.delete_file() return elif (mytext.lower() == 'delete directory'): modules.delete_dir() return else: formatting.text_box('Invalid Command!') return
def file_type(): formatting.line() file_name = input("Enter the name of file: ") formatting.line() list = os.listdir('.') if file_name in list: formatting.line() subprocess.call(["file", file_name]) formatting.line() return else: formatting.text_box("The file is not in current Directory") return
def create_user(): import crypt formatting.line() user_name = input("Enter user name: ") formatting.line() user_password = input("Enter password: "******"sudo useradd -m " + user_name + " -p " + encrypted_password try: os.system(user_add) return except: formatting.text_box("Problem creating user!") return
def create_file(): temp = 'y' formatting.line() file_name = input('Enter the name of file: ') formatting.line() temp = input("Are you sure to create file with name " + file_name + "(Y/n): ") formatting.line() if temp == 'n' or temp == 'N': formatting.text_box("File not created!") return else: subprocess.call(["touch", file_name]) formatting.text_box("File with name " + file_name + " created Successfully!") return
def speech_to_text(flag=0): r = sr.Recognizer() with sr.Microphone() as source: if (flag == 1): subprocess.call(['clear']) formatting.show_list() formatting.text_box('Listening...') audio = r.listen(source) try: mytext = r.recognize_google(audio) return mytext except sr.UnknownValueError: formatting.text_box( 'Google Speech Recognition could not understand audio') return 0 except sr.RequestError as e: formatting.text_box( 'Could not request results from Google Speech Recognition service; {0}' .format(e)) return 0
def list_files(): list = os.listdir('.') formatting.head('Files in current Directory') for i in range(len(list)): formatting.text_box(list[i]) return
def back(): os.chdir("../") formatting.text_box(os.getcwd()) return
def current_working_dir(): path = os.getcwd() formatting.text_box(path) return
def delete_user(): formatting.line() user_name = input("Enter user name: ") formatting.line() del_user = subprocess.call(["sudo", "deluser", user_name]) formatting.text_box("User: "******" deleted Successfully!")
def shutdown_now(): formatting.text_box("Shutting down the computer...") subprocess.call(["shutdown", "-h", "now"]) return
if __name__ == '__main__': flag = 1 welcome_window() input('Press Enter to continue...') subprocess.call(['clear']) while 1: # if (flag == 1): mytext = voice.speech_to_text(1) flag = 0 else: mytext = voice.speech_to_text() # Checking Errors if (voice.error_status(mytext)): formatting.text_box('Please, try again!') continue # Checking exit elif (mytext == 'exit'): formatting.text_box('Good Bye!') voice.text_to_speech('Good Bye!') exit() # calling the functionality else: subprocess.call(['clear']) execute(mytext) input('Press Enter to continue...') subprocess.call(['clear'])