-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.py
146 lines (121 loc) · 3.92 KB
/
file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import pyttsx3
import speech_recognition as sr
import webbrowser
import datetime
import pywhatkit
import os
import yfinance as yf
import pyjokes
# Listen to Microphone & return the audio as text using google
def transform():
r = sr.Recognizer();
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
r.pause_threshold = 0.8
said = r.listen(source)
try:
print("I am listening")
q = r.recognize_google(said, language="en")
return q
except sr.UnknownValueError:
print("Sorry, I did not understand")
print("I am waiting")
except sr.RequestError:
print("Sorry, the service is down")
print("I am waiting")
except:
print("I am waiting")
def speaking(message):
engine = pyttsx3.init()
engine.say(message)
engine.runAndWait()
# engine = pyttsx3.init()
# for voice in engine.getProperty('voices'):
# print(voice)
# Return the weekday name
def query_day():
date = datetime.date.today()
#print(date)
weekday = date.weekday()
#print(weekday)
mapping = {
0:'Monday',1:'Tuesday',2:'Wednesday',3:'Thursday',4:'Friday',5:'Saturday',6:'Sunday'
}
try:
print(f"Today is {mapping[weekday]}")
speaking(f"Today is {mapping[weekday]}")
except:
pass
# Returns the time
def query_time():
time = datetime.datetime.now().strftime("%I:%M:%S")
print(f"It's {time[0:2]}:{time[3:5]} right now")
speaking(f"It's {time[0:2]} {time[3:5]} right now")
# Intro greeting at startup
def whatsup():
speaking('''Hey, my name is Ganky. I'm your personal assistant.
How may I help you?
''')
# The Heart of Assistant. dont break </3. Takes queries & returns answers. Very smart. Toddler
def querying():
whatsup()
start = True
while(start):
q = transform().lower()
if "who are you" in q:
whatsup()
continue
elif "your name" in q:
speaking("I'm Ganky. Your Virtual Assistant")
continue
elif "youtube" in q:
speaking("Opening YouTube")
webbrowser.open('https://www.youtube.com/')
continue
elif "browser" in q:
speaking("Opening Web Browser")
webbrowser.open('https://www.google.com/')
continue
elif "what day" in q:
query_day()
continue
elif "what time" in q:
query_time()
continue
elif "shutdown" in q:
print("Shutting down")
speaking("Shutting down")
break
elif "wikipedia" in q:
speaking("Checking wikipedia")
q = q.replace("wikipedia","")
result = wikipedia.summary(q,sentences=2)
speaking("Found on wikipedia")
speaking(result)
continue
elif "search" in q:
speaking("Searching on google")
pywhatkit.search(q)
speaking("This is what I found")
continue
elif "joke" in q:
speaking(pyjokes.get_joke())
continue
elif "play" in q:
speaking(f"playing {q}")
pywhatkit.playonyt(q)
continue
elif "stock prices" in q:
search = q.split("of")[-1].strip()
lookup = {'apple':'APPL',
'amazon': 'AMZN',
'google':'GOOGL'}
try:
stock = lookup[search]
stock = yf.Ticker(stock)
currentprice = stock.info["regularMarketPrice"]
speaking(f"found it. The price for {search} is {currentprice}")
continue
except:
speaking("Sorry, I have no data for {search}")
continue