PyCharm Project

 from email.mime.text import MIMEText

from email.utils import formataddr
from builtins import print
import os
import subprocess
from smtplib import SMTP
import pywhatkit as kit
import re
import requests
import pyjokes
import pyautogui
import smtplib
import wikipedia
import datetime
import pyttsx3
import webbrowser as wb
from PIL import Image,ImageTk,ImageSequence
from tkinter import *
import tkinter
import tkinter as tk
from tkinter.scrolledtext import ScrolledText

root = Tk()
hourr = datetime.datetime.now().hour


# IMPORTANTS
u2URL='https://www.youtube.com/results?search_query='
Api_Key = '2a49dac8859a64155b0fd13e932601cb'
pattern="(open)"
pattern2='(what|who|when|do|did|can|is)'
pattern3='(show videos of|show video of)'
pattern4='(search|search for)'

def speak(texttospeak):
important = pyttsx3.init()
important.setProperty("rate", 110)
important.say(texttospeak)
important.runAndWait()

class start():
def __init__(self):
self.root = root

self.label = tkinter.Label(root,text='>>', bg='black', fg='green', font=('bold')).place(x=0, y=338, width=41, height=30)
self.entryIput = Entry(root, font=("times new roman", 15, 'bold'), bg='black', bd=0, fg='white', width=30)
self.entryIput.place(x=40.5, y=335, width=372, height=33)
ok_btn = Button(root, text='>>>', command=self.directPoint, bg='black', fg='white', bd=0, font=("times new roman", 13, 'bold'), width=20)
ok_btn.grid(row=10, columnspan=3, sticky=SE)
if hourr >= 0 and hourr < 11:
# speak("Good Morning Sir")
txt.insert(0.0, "Good Morning sir\n")
elif hourr >= 12 and hourr < 15:
# speak("Good afternoon sir")
txt.insert(0.0, "Good afternoon sir\n")
elif hourr >= 16 and hourr < 24:
speak("Good evening sir")
txt.insert(0.0, "Good evening sir\n")
else:
speak("Good night sir")
txt.insert(0.0, "Good night sir\n")

def directPoint(self):

text = self.entryIput.get()
if text == "time":
hour = datetime.datetime.now().hour
minute = datetime.datetime.now().minute
format12hour = 0
AmorPm = ''
if hour >= 0 and hour < 12:
AmorPm = 'A M'
else:
format12hour=hour-12
AmorPm = 'P M'

total = (str(format12hour)+ " " + str(minute) + str(AmorPm))
txt.insert(0.0, total + "\n")
speak(total)

elif text == 'date':
Year = (datetime.datetime.now().year)
Month = (datetime.datetime.now().month)
Day =(datetime.datetime.now().day)

string= str(Year)+" "+str(Month)+" "+str(Day)

speak(string)

txt.insert(0.0,string)

elif text == 'remember':
speak("what do you want me to remember")
remem = open('data.txt', 'w')
remem.write(self.entryIput.get())
remem.close()

remem = open('data.txt', 'r')
speak(remem.read())
txt.insert(0.0,remem.read()+"\n")

elif re.search("weather in| weather of", text):

city = re.sub(pattern='weather in| weather of'+'[\s]', repl='', string=text)

LinkAdd = 'http://api.openweathermap.org/data/2.5/weather?q=' + city + '&appid=' + Api_Key

Api_Link = requests.get(LinkAdd)
Response = Api_Link.json()

humidity = Response['main']['humidity']

temperature = int(Response['main']['temp'] - 273.1)

phrase = Response['weather'][0]['description']

speak("currently in, " + city + " temperature is ," + str(
temperature) + " degree celsius " + " ,humidity is " + str(
humidity) + " percent and sky is " + phrase)

txt.insert(0.0,"currently in " + city + " temperature is " + str(
temperature) + " degree celsius " + " humidity is " + str(
humidity) + " percent and sky is " + phrase+"\n")

elif text == 'email':

toAdd = 'mercysunandha14@gmail.com'
toName = 'Mercy'
fromAdd = 'stylishcharan2@gmail.com'
fromName = 'Charan'


try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('stylishcharan2@gmail.com', 'stylishcharan1234')
server.sendmail(fromAdd, toAdd, 'hello')
txt.insert(0.0,"ok sir email sent\n")
except Exception as e:
txt.insert(0.0, str(e)+"\n")

elif re.search(pattern2, text):
question = re.sub(pattern2, repl='', string=text)
question = question.replace("wikipedia", "")
answer = wikipedia.summary(question, sentences=2)
speak(answer)
txt.insert(0.0, answer+"\n")

elif text == 'notepad':
subprocess.call(text + ".exe")
txt.insert(0.0,"Opening Notepad\n")
#Google search
elif re.search(pattern4, text):

searchInGoog = re.sub(pattern=pattern4+'[\s]', repl='', string=text)

kit.search(searchInGoog)
speak("showing results of "+searchInGoog)
txt.insert(0.0, "showing results of "+searchInGoog+"\n")
# youtube
elif re.search("play", text):

searchInU2 = re.sub(pattern="play"+'[\s]', repl='', string=text)
finalizedOut = re.sub(pattern='[\s]+', repl=' ', string=searchInU2)
if finalizedOut == text:
pass
else:
print(finalizedOut , searchInU2)
kit.playonyt(finalizedOut)
speak("playing "+searchInU2)
txt.insert(0.0, "playing "+searchInU2+"\n")
# just Videos
elif re.search(pattern3, text):

searchInU2 = re.sub(pattern=pattern3+'[\s]', repl='', string=text)
finalizedOut = re.sub(pattern='[\s]+', repl='+', string=searchInU2)
if finalizedOut == text:
pass
else:
wb.open(u2URL+finalizedOut)
speak("showing videos of "+searchInU2)
txt.insert(0.0, "showing videos of "+searchInU2+"\n")
#Website
elif re.search(pattern, text):
searchIt=re.sub(pattern='(open)+[\W\w]', repl='', string=text)

if searchIt == 'amazon':
wb.open("www." + searchIt + ".in")
else:
wb.open("www." + searchIt + ".com")
speak("Opening "+searchIt)
txt.insert(0.0,"Opening "+ searchIt +"\n")
elif text == "logout":
os.system("shutdown - 1")
txt.insert(0.0, "Logging out sir\n")
elif text == "shutdown":
os.system("shutdown /s /t 1")
txt.insert(0.0, "shutting down\n")
elif text == "restart":
os.system("shutdown /r /t 1")
txt.insert(0.0, "restarting\n")
elif text == 'screenshot':
img = pyautogui.screenshot()
img.save("F:\spotify\Test.jpg")
txt.insert(0.0,"Screenshot captured sir!!\n")
elif text == 'joke':
jok=pyjokes.get_joke()
speak(jok)
txt.insert(0.0,jok+"\n")
elif text == 'songs':
songs_dir = "F:\spotify"
songs = os.listdir(songs_dir)
os.startfile(os.path.join(songs_dir, songs[4]))
txt.insert(0.0, "Playing song\n")
else:
txt.insert(0.0, text+"\n")
speak(text)

txt = ScrolledText(root, wrap=WORD, width=75, height=21, bg='black', fg='lightgreen', bd=0)
txt.grid(row=3, columnspan=2, sticky=W)

obj=start()
root.title('F.R.I.D.A.Y')
root.geometry("600x370")
root.resizable(False,False)
root.mainloop()

Comments

Popular posts from this blog

Android Eclipse Project L.O.R.A

APP