-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.py
More file actions
134 lines (116 loc) · 5.08 KB
/
commands.py
File metadata and controls
134 lines (116 loc) · 5.08 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
from time import ctime
from listener import Listener
from timer import Timer, Notification
from utils import respond
import os
import datetime
path = "/Users/rileythompson//Desktop/Einstein/" #SET YOUR OWN PATH TO EINSTEIN
class Commands():
def __init__(self, listener:Listener):
self.sleep = False
self.listener = listener
def understand(self, data) -> None:
if "nevermind" in data:
data = data.split('nevermind')[-1]
if "stop listening" in data:
print('Listening stopped')
respond("Okay shutting down")
self.listener.listening = False
return
if "hey Einstein" in data or "Einstein you there?" in data:
respond("yes?")
self.sleep = False
elif not self.sleep:
if "what time is it" in data or "what's the time" in data or 'what is the time' in data:
respond(ctime())
elif "okay thank you" in data:
self.sleep = True
respond("You're welcome. say 'hey Einstein' if you need more help")
elif "go to sleep" in data:
self.sleep = True
respond("Say 'hey Einstein' to wake me")
elif "write a note" in data:
respond("What should i write?")
note = self.listener.listen()
file = open('notes.txt', 'w')
respond("Should I include the time?")
answer = self.listener.listen()
if 'yes' in answer or 'sure' in answer or 'yeah' in answer:
strTime = datetime.datetime.now().strftime("% H:% M:% S")
file.write(strTime)
file.write(" :- ")
file.write(note)
respond("Note saved")
elif "show note" in data or "read note" in data or "show notes" in data or "read notes" in data:
respond("Reading notes")
file = open("notes.txt", "r")
read_back = file.read()
if read_back:
respond(read_back)
else:
respond("Nothing in your notes")
elif "calculate" in data:
data = data.lstrip('calculate ')
calculation = eval(data)
print(calculation)
respond(data + " is " + str(calculation))
elif "help me" in data or "show commands" in data or "what do i do" in data or "list commands" in data:
file = open(path+"help.txt", "r")
read_back = file.read()
print(read_back)
respond(read_back)
elif "record" in data or "start recording" in data:
respond("Recording now")
recording = ""
listening = True
while listening:
chunk = self.listener.listen()
if 'Einstein stop recording' in chunk:
recording += data.strip('Einstein stop recording') #TODO this will break it
break
recording += chunk
file = open('recording.txt', 'w')
respond("Should I include the time?")
answer = self.listener.listen()
if 'yes' in answer or 'sure' in answer or 'yeah' in answer:
strTime = datetime.datetime.now().strftime("% H:% M:% S")
file.write(strTime)
file.write(" :- ")
file.write(recording)
respond("Note saved")
elif "playback" in data:
respond("Playing back recording")
file = open("recording.txt", "r")
read_back = file.read()
if read_back:
respond(read_back)
else:
respond("Nothing in your notes")
elif "set a timer" in data or 'set an alarm' in data:
data = data.lstrip("set a timer")
data = data.lstrip(" for ")
timer = Timer()
timer.set_time(data)
pid = os.fork()
if pid > 0:
print(1)
respond("Okay timer set")
else:
print(0)
timer.alert()
os._exit(0)
elif "set a notification" in data or 'notify me' in data or 'remind me' in data or 'set a reminder' in data:
respond("okay what would you like the message to say?")
message = self.listener.listen()
notification = Notification()
notification.set_time(data)
notification.set_message(message)
pid = os.fork()
if pid > 0:
respond("Okay notification set")
else:
notification.alert()
os._exit(0)
else:
print('Unable to process command')
respond("Sorry I did not get that")