-
Notifications
You must be signed in to change notification settings - Fork 1
/
FallScript.py
170 lines (143 loc) · 3.88 KB
/
FallScript.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
161
162
163
164
165
166
167
168
169
170
#C:\Users\bsdueck\Dropbox\IFTTT
from pathlib import Path
import os
import time
import winsound
yes_file = Path("IFTTT\\yes.txt")
no_file = Path("IFTTT\\no.txt")
fall_file = Path("IFTTT\\actualfall.txt")
def checkfile():
#check if there is a yes file that exists
if yes_file.is_file():
time.sleep(1)
while True:
try:
os.remove(yes_file)
break
except:
pass
return 1
#check if there is a no file that exists
elif no_file.is_file():
time.sleep(1)
while True:
try:
os.remove(no_file)
break
except:
pass
return 2
#there is no file
else:
return 0
#ARE YOU OKAY?
def AreYouOkay():
winsound.PlaySound('wavfile\\AreYouOk.wav', winsound.SND_FILENAME)
start = time.clock()
while True:
end = time.clock()
bool = checkfile()
if ((end-start) > 20):
#PLAY LOUD NOISE and say i havent detected anything
winsound.PlaySound('wavfile\\AreYouOk.wav', winsound.SND_FILENAME)
bool = noInput()
if bool != 0:
if bool == 1:
#if they are okay ask if they are in any pain
print("$ - The person said yes")
pain()
elif bool == 2:
#if they are not, call emergency
print("$ - The Person Said No")
Emergency()
def pain():
winsound.PlaySound('wavfile\\AnyPain.wav', winsound.SND_FILENAME)
start = time.clock()
while True:
end = time.clock()
bool = checkfile()
if ((end-start) > 20):
#PLAY LOUD NOISE and say i havent detected anything
winsound.PlaySound('wavfile\\AnyPain.wav', winsound.SND_FILENAME)
bool = noInput()
if bool != 0:
if bool == 1:
#the person said they are in pain, emergency
print("$ - The person said yes")
Emergency()
elif bool == 2:
#if they are not, ask if they can get up
print("$ - The Person Said No")
CanYouGetUp()
def CanYouGetUp():
winsound.PlaySound('wavfile\\CanYouGetUp.wav', winsound.SND_FILENAME)
start = time.clock()
while True:
end = time.clock()
bool = checkfile()
if ((end-start) > 20):
#PLAY LOUD NOISE and say i havent detected anything
winsound.PlaySound('wavfile\\CanYouGetUp.wav', winsound.SND_FILENAME)
bool = noInput()
if bool != 0:
if bool == 1:
#the person said they can get up, check to see if up
print("$ - The person said yes")
WaitTillUp()
elif bool == 2:
#if they are not, call emergency
print("$ - The Person Said No")
Emergency()
def Emergency():
winsound.PlaySound('wavfile\\Emergency.wav', winsound.SND_FILENAME)
os.remove(fall_file)
exit()
def noInput():
start = time.clock()
while True:
end = time.clock()
bool = checkfile()
if ((end-start) > 20):
bool = 2
Emergency()
if bool != 0:
if bool == 1:
return bool
elif bool == 2:
#if they are not, call emergency
return bool
#print("$ - The Person Said No")
#Emergency()
def WaitTillUp():
#add the logic for yes and no
time.sleep(5)
areYouDizzy()
exit()
def areYouDizzy():
winsound.PlaySound('wavfile\\NowUpPainOrDizziness.wav', winsound.SND_FILENAME)
start = time.clock()
while True:
end = time.clock()
bool = checkfile()
if ((end-start) > 20):
#PLAY LOUD NOISE and say i havent detected anything
winsound.PlaySound('wavfile\\NowUpPainOrDizziness.wav', winsound.SND_FILENAME)
bool = noInput()
if bool != 0:
if bool == 2:
#the person said they can get up, check to see if up
print("$ - The person said no")
winsound.PlaySound('wavfile\\AllClear.wav', winsound.SND_FILENAME)
os.remove(fall_file)
exit()
elif bool == 1:
#if they are dizzy or in pain, call emergency
print("$ - The Person Said Yes")
Emergency()
######################
##MAIN
######################
#need to check for file
while True:
if fall_file.is_file():
AreYouOkay()