-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBX_MainMenuGUI1.py
More file actions
332 lines (295 loc) · 13.7 KB
/
BX_MainMenuGUI1.py
File metadata and controls
332 lines (295 loc) · 13.7 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env python3
#-------------------------------------------------------------------------------------
# B.A.X.T.E.R A.I System
#-------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------
# Table Of Contents/Overview
#----------------------------------------------------------------------------------------------
# Imports
# Commander & A.I Name
# WishMe Function
# Main
# - General Conversation, Jokes, & Fun Facts
# -- Search Wikipedia
# --- Search Wolfram Alpha
# ---- Open Stuff on Internet
# ----- Open Stuff on Computer
# ------ Set Reminders & Renewals
# ------- Set ToDo
# -------- Send E-mails
# --------- Stop Program
# Run Program
#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------
# TODO
#----------------------------------------------------------------------------------------------
# (1)
# Add More Convo Abilities
# Iterate through pairs.py to do general convo and fix it's output to match the standard format
# Memory Capabilities via Info stored/retrieved in a SQL Database
# Open CV & Guesture Controls??
# (2)
# Setup GUI that takes in Constants (User's Name, DOB, E-Mail, Ect..) & Stores them in Constants.db
# (3)
# Track packages with Baxter - put tracking # in database and have Baxter check on it when updated
# Track prices of items and sends an Email when the price drops
# (4)
# Access to BAXTER via discord or Email.
# Ex: https://realpython.com/how-to-make-a-discord-bot-python/
# (5)
# Renewals & Renewal Reminders via Email, or msg Service Like Discord & Popup msgBox via PyQT
# (6)
# Implement Google/Custom Calendar, so user can add appointments, b-days, events, ect..
# & Have alerts display/popup when events are coming up (1 day & 2-3h before hand)
# Ex: https://pypi.org/project/gcalcli/
# Set Reminders on Google Calendar so they can be view on MagicMirror
# Allow user to better set reminders (pick day, time & repeat times)
# (7)
# Figure out Multitasking!!
#----------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------------
import json
import random
import datetime
import operator
import os
import subprocess
import time
import threading
import sys
import sched
import webbrowser
import requests
from bs4 import BeautifulSoup
import wikipedia
import wolframalpha
from BX_Intents import (greetings, farewell, thanks, noAnswer, youChoose)
from BX_External_Functions import (autoTypeAnimation, StartupText, ShutdownText,
UserInput, listen, speak, getRandomJoke, getFunFacts,
setReminders, setTodo, terminateTimers, sendEmail,
wishMe, setRenewal, ErrorMsg, offlineWarningMsg,
schedule_reminder)
# Print a warning msg if there is no internet to prevent pywhatkit
# from crashing the program due to no connection
try:
import pywhatkit
except:
offlineWarningMsg()
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
# Main
#-------------------------------------------------------------------------------------
def BAXTER():
command = UserInput()
command=str(command).lower()
#-------------------------------------------------------------------------------------
# General Conversation (From Intents.py)
#-------------------------------------------------------------------------------------
#Greetings
patterns, responses = greetings()
if (command in patterns):
results = (random.choice(responses))
autoTypeAnimation(results)
speak(results)
#Farewell
patterns, responses = farewell()
if (command in patterns):
results = (random.choice(responses))
autoTypeAnimation(results)
speak(results)
#Thanks
patterns, responses = thanks()
if (command in patterns):
results = (random.choice(responses))
autoTypeAnimation(results)
speak(results)
#No Response
patterns, responses = noAnswer()
if (command in patterns):
results = (random.choice(responses))
autoTypeAnimation(results)
speak(results)
#-------------------------
# Tell a Joke
#-------------------------
if ('joke' in command):
try:
joke = getRandomJoke()
autoTypeAnimation(joke)
speak(joke)
return
except:
ErrorMsg("get", "jokes")
#-------------------------
#-------------------------
# Tell a Fun Fact
#-------------------------
if ('fact' in command):
try:
funFact = getFunFacts()
autoTypeAnimation(funFact)
speak(funFact)
return
except:
ErrorMsg("get", "fun facts")
#-------------------------
#-------------------------------------------------------------------------------------
# Search Wikipedia (General Info)
#-------------------------------------------------------------------------------------
if ('weather' not in command):
if ('who is' in command) or ('what is the' in command) or ('what is a' in command) or ("what is" in command):
if ('time' not in command):
if ('news' not in command):
autoTypeAnimation('Searching Wikipedia...')
speak('Searching...')
command = command.replace("who is","")
command = command.replace("what is the","")
command = command.replace("what is a","")
command = command.replace("what is","")
try:
results = wikipedia.summary(command, sentences = 2)
autoTypeAnimation(results)
speak(results)
except:
ErrorMsg("connect to", "Wikipedia")
#-------------------------------------------------------------------------------------
# Search Wolfram Alpha (Math/Conversions, Definitions)
#-------------------------------------------------------------------------------------
if ('news' not in command):
if ('weather' in command) or ('calculate' in command) or ("what's" in command) or ('define' in command) or ("what" in command):
autoTypeAnimation('Searching Wolfram Alpha...')
speak('Searching...')
command = command.replace("calculate","")
command = command.replace("what's","")
command = command.replace("define","")
# Wolframalpha App Id
appId = 'JH9XHR-W9J76L7H5A'
try:
# Wolfram Instance
client = wolframalpha.Client(appId)
res = client.query(''.join(command))
results = next(res.results).text
autoTypeAnimation(results)
speak(results)
except:
ErrorMsg("connect to", "Wolfram Alpha database")
#-------------------------------------------------------------------------------------
# Open Stuff on the Internet
#-------------------------------------------------------------------------------------
#Open Youtube Videos (Ex: 'Play __ on youtube')
if ('youtube' in command):
autoTypeAnimation("Launching Youtube...")
speak('Launching Youtube')
command = command.replace("youtube","")
try:
pywhatkit.playonyt(command)
except:
ErrorMsg("connect to", "Youtube")
#Open Google Maps and Find The Location of A You Want
if ('where is' in command):
command = command.replace("where is","")
autoTypeAnimation("Locating" + command + "...")
speak('Locating' + command)
webbrowser.open_new_tab("https://www.google.com/maps/place/" + command)
#Search Stuff on Google
if ('search' in command):
command = command.replace("search", "")
autoTypeAnimation("Searching" + command + " on Google")
speak('Searching' + command)
try:
pywhatkit.search(command)
except:
ErrorMsg("connect to" , "Google")
#Close Firefox
if ('close firefox' in command):
autoTypeAnimation("Terminating Firefox...")
speak('Closing Firefox')
command = command.replace("close firefox", "")
browser = "firefox.exe"
try:
os.system("taskkill /f /im " + browser)
except:
ErrorMsg("close", "Firefox")
#-------------------------------------------------------------------------------------
# Open Stuff on the Computer
#-------------------------------------------------------------------------------------
#Open Windows Media Player and Auto Play the Playlist Called Music
if ('play music' in command) or ('media player' in command) or ('drop the needle' in command):
autoTypeAnimation("Launching music...")
speak("Launching Music")
command = command.replace("play music", "")
command = command.replace("media player", "")
command = command.replace("drop the needle", "")
try:
subprocess.Popen("C:\Program Files (x86)\Windows Media Player\wmplayer.exe /Playlist Music")
except:
ErrorMsg("open","Windows Media Player")
#Close Windows Media Player
if ('stop music' in command):
autoTypeAnimation("Terminating music...")
speak('Closing Music')
command = command.replace("stop music", "")
mediaPlayer = "wmplayer.exe"
try:
os.system("taskkill /f /im " + mediaPlayer)
except:
ErrorMsg("close", "Windows Media Player")
#-------------------------------------------------------------------------------------
# Set Reminders & Renewals
#-------------------------------------------------------------------------------------
if ('remind me' in command) or ('reminder' in command) or ('renew' in command):
command = command.replace("remind me to", "")
#If renew is mentioned in the command call the setRenewal Function
if ('renew' in command):
setRenewal()
#Else, call the setReminders Function
else:
setReminders() #Call setReminders() from External Functions
#-------------------------------------------------------------------------------------
# Set ToDo
#-------------------------------------------------------------------------------------
if ('todo' in command):
command = command.replace("add", "")
command = command.replace("to the todo list", "")
setTodo(command) #Call setTodo() from External Functions
#-------------------------------------------------------------------------------------
# Send E-Mails
#-------------------------------------------------------------------------------------
if ('email' in command):
command = command.replace("email", "")
sendEmail() #Call send E-Mail function fro External Functions
#-------------------------------------------------------------------------------------
# Stop Program/Script Command
#-------------------------------------------------------------------------------------
if ('stop' in command) or ('shutdown' in command) or ('quit' in command):
speak("Shutting Down...")
results = "Terminating program..."
autoTypeAnimation(results)
ShutdownText()
terminateTimers()
exit()
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
# Run The Program
#------------------------------------------------------------------------------------------
def Main():
StartupText()
wishMe()
speak("How may I be of service?")
while True:
BAXTER()
def Reminders():
scheduler = sched.scheduler(time.time, time.sleep) #Create Schedule
schedule_reminder(scheduler) #Run Reminders
while True:
scheduler.run(False)
while not scheduler.empty():
scheduler.run(False)
# #Works but Slow. Especially on Startup.
# threading.Thread(target=Main).start()
# threading.Thread(target=Reminders).start()
# threading.Thread(target=Test).start()
#------------------------------------------------------------------------------------------