def start(): print("=> Hello, This is SPRITAN a chatbot AI") speak_it("Hello, This is SPRITAN a chatbot AI") print("=> Feel free to say hi or command me to do something") speak_it("Feel free to say hi or command me to do something") print( "-------------------------------------------------------------------------------------" )
def web_s(query): if 'youtube' in query: speak_it('Opeaning Youtube') print("SPRITAN => Opeaning Youtube") webbrowser.open("https://www.youtube.com/", new=2) elif 'google' in query: webbrowser.open("https://www.google.com/", new=2) elif 'stackoverflow' in query: webbrowser.open("https://stackoverflow.com", new=2)
def wishMe(): hour = int(datetime.datetime.now().hour) if hour >= 0 and hour < 12: speak_it("Good Morning!") elif hour >= 12 and hour < 18: speak_it("Good Afternoon!") else: speak_it("Good Evening!")
def wiki(query): speak_it('Searching Wikipedia...') print("Searching Wikipedia...") query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=2) speak_it("According to Wikipedia") print("SPRITAN => According to Wikipedia") print(results) speak_it(results)
def get_respond(u_input): try: a2=(u_input,) #converting string to tuple mycursor.execute(sqlformula2,a2) myresult=mycursor.fetchone() str_myresult=convertTuple(myresult) return str_myresult except mysql.connector.Error as err: print("You => Sir, would you like to teach me the answer ?") speak_it(" Sir, would you like to teach me the answer?") print("\t\tPress y for yes and n for no") speak_it("Press y for yes and n for no") ch = input("You => ") if ch=='y' or ch=='Y': print("You => Please type the answer.") speak_it("Please type the answer") p_output = input("You => ") add_respond(u_input, p_output) return "Thanks for teaching me." elif ch=='N' or ch=='n': return "Hopefully I will learn it someday."
requestAIs="" i=0 # working wishMe() start() while requestAIs!="exit": flag = 0 requestAI=input("You => ") requestAIs=requestAI.lower() #can be changed latter if 'wikipedia' in requestAIs: wiki(requestAIs) elif 'send email' in requestAIs: try: to = input("To: ") speak_it("What should I say?") content = input() sendEmail(to, content) speak_it("Email has been sent!") except Exception as e: print(e) speak_it("Sorry my friend. I am not able to send this email") elif 'web open' in requestAIs: web_s(requestAIs) elif requestAIs == "exit": print("Goodbye take care") speak_it("Goodbye, take care") elif 'current' in requestAIs:
#fuction to convert string to tuple def convertTuple(tup): str = functools.reduce(operator.add, (tup)) return str #fuctions to input def add_respond(u_input,p_output): a1 = (u_input, p_output) mycursor.execute(sqlformula,a1) mydb.commit() #function to output def get_respond(u_input): a2=(u_input,) #converting string to tuple mycursor.execute(sqlformula2,a2) myresult=mycursor.fetchone() str_muresult=convertTuple(myresult) return myresult k = "are you happy?" p_output = get_respond(k) speak_it(p_output) print(p_output)
def weather_report(city_name='Golaghat'): # complete_url variable to store # complete url address complete_url = base_url + "appid=" + api_key + "&q=" + city_name # get method of requests module # return response object response = requests.get(complete_url) # json method of response object # convert json format data into # python format data x = response.json() # Now x contains list of nested dictionaries # Check the value of "cod" key is equal to # "404", means city is found otherwise, # city is not found if x["cod"] != "404": # store the value of "main" # key in variable y y = x["main"] # store the value corresponding # to the "temp" key of y current_temperature = y["temp"] # store the value corresponding # to the "pressure" key of y current_pressure = y["pressure"] # store the value corresponding # to the "humidity" key of y current_humidiy = y["humidity"] # store the value of "weather" # key in variable z z = x["weather"] # store the value corresponding # to the "description" key at # the 0th index of z weather_description = z[0]["description"] # output following values print("SPRITAN => Temperature (in kelvin unit) = " + str(current_temperature) + "\n\t atmospheric pressure (in hPa unit) = " + str(current_pressure) + "\n\t humidity (in percentage) = " + str(current_humidiy) + "\n\t description = " + str(weather_description)) speak_it(" Temperature (in kelvin unit) = " + str(current_temperature) + "\n atmospheric pressure (in hPa unit) = " + str(current_pressure) + "\n humidity (in percentage) = " + str(current_humidiy) + "\n description = " + str(weather_description)) else: speak_it(" City Not Found ") print("SPRITAN => City Not Found ")
# Global Variables requestAI="" requestAIs="" i=0 # working wishMe() start() while requestAIs!="exit": flag = 0 print("SPRITAN => Sir, would you like speak or type for commanding\n\t\t press 1 to speak and 2 to type") speak_it("Sir, would you like to speak or type for commanding. press 1 to speak and 2 to type") ch = input("You => ") # Checking for voice and text if ch == "1": print("SPRITAN => Plz Speak.") speak_it('Please Speak') requestAI = takeCommand() print("You => "+requestAI) elif ch == "2": print("SPRITAN => Plz Command.") speak_it('Please command') requestAI = input("You => ") requestAIs=requestAI.lower() #can be changed latter if 'wikipedia' in requestAIs: