-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueryResponder.py
160 lines (141 loc) · 4.95 KB
/
queryResponder.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from notify import notify
from re import match,sub
from audioOutput import speak,speakWiki
from _thread import start_new_thread
from subprocess import getoutput
def search(Input):
# no data received
if Input == "":
notify(message="Sorry! Did you say something?")
return
# Command for quiting
if Input in ['quit', 'terminate']:
speak("Bye")
Input = 'terminate'
return
#Command to lock PC
if Input in ['lock','lock my mac','lock my pc']:
speak("See you soon")
getoutput("/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend")
return
#Command to reboot
if Input in ['reboot', 'reboot my mac', 'reboot my pc']:
speak("See you soon")
getoutput("osascript -e 'tell application \"System Events\" to restart'")
return
# Command to shutdown
if Input in ['shutdown', 'shutdown my mac', 'shutdown my pc']:
speak("See you soon")
getoutput("osascript -e 'tell application \"System Events\" to shut down'")
return
# Command for Self Intoduction
if Input in ["who are you", "introduce yourself", "describe yourself"]:
answer = 'I am Nancy, your personal assistant.'
notify(title=Input, subtitle='I got this:', message=answer)
speak(answer)
return
# Command for Owner Information
if Input in ["who created you", "who is your master", "who is your owner"]:
answer = "Team Errorist created me, Although I'm open source!"
notify(title=Input, subtitle='I got this:', message=answer)
speak(answer)
return
# Command for opening maps
if match(r"^open maps.*$", Input):
from webHandler import openMaps
Input = Input.replace("open maps", " ")
openMaps(Input)
speak("Here It is...")
return
# Command for downloading lyrics
if match(r"^download lyrics.*$", Input):
from lyrics import lyrics_down
lyrics_down(Input)
return
#Command to open Applications
if match(r"^execute.*$",Input):
from fInderAndAppControl import openApp
Input=Input.replace("execute ","")
openApp(Input)
speak('There you go')
return
#Command to open a file
if match(r"^open file.*$",Input):
Input=Input.replace("open file ","")
from fInderAndAppControl import openFile
openFile(Input)
return
#Command to open a directory
if match(r"^open folder.*$",Input):
Input=Input.replace("open folder ","")
from fInderAndAppControl import openFolder
openFolder(Input)
return
#Command to play a song
if match(r"^play song.*$",Input):
Input=Input.replace("play song ","")
from fInderAndAppControl import openFile
openFile(Input,direc="Music")
return
#Command to play video
if match(r"^play video.*$",Input):
Input=Input.replace("play video ","")
from fInderAndAppControl import openFile
openFile(Input,direc="Movies")
return
# Commamnd for browsing a website
if match(r"^browse.*$", Input):
from webHandler import browseUrl
Input = Input.replace("browse ", " ")
browseUrl(Input)
return
# Command to throw a dice
if match(r"^throw a dice$", Input):
from randomStuff import dice
output = str(dice())
notify(message=output)
speak(output)
return
# Command to toss a coin
if match(r"^toss a coin$", Input):
from randomStuff import coin
output = coin()
notify(message=output)
speak(output)
return
# Command to download mp3 song
if match(r"^download (audio)|(song).*$", Input):
from mp3Download import page_link
Input = sub(r"download audio|song|mp3 ", '', Input)
#page_link(Input)
start_new_thread(page_link,(Input,))
return
# Command to download mp4 video
if match(r"^download video.*$", Input):
from mp4Download import youtube_link
Input = sub(r"download video ", '', Input)
#youtube_link(Input)
start_new_thread(youtube_link,(Input,))
return
# Command to read it aloud
if match(r"^(read out)|(speak out loud)$", Input):
from pyperclip import paste
speak(paste())
return
try:
from settings import client
print('Trying wolframalpha')
result = client.query(Input)
answer = next(result.results).text
notify(title=Input, subtitle='I got this:', message=answer)
speak(answer)
except:
try:
print('Trying wikipedia')
from wikipedia import summary
answer = summary(Input, sentences=1)
print(answer)
notify(title=Input, subtitle='I got this:', message=answer)
speakWiki(answer)
except Exception as err:
notify(message='Opps Nothing Found', extra='-timeout 1')