-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAHF_Notifier.py
55 lines (46 loc) · 2.5 KB
/
AHF_Notifier.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
import requests
from time import sleep
class AHF_Notifier:
"""
Sends a text message using a web service, textbelt.com
AHF_Notifier needs requests module, which is not installed by default.
The best way to install python modules is with pip. Assuming you are using Python 3:
sudo apt-get install python3-pip
sudo pip-3.2 install requests
"""
def __init__ (self, cageID_p, phoneList_p):
"""Makes a new AHF_Notifier object
The notifier will send text messages to a tuple of phone numbers using a web service, textbelt.com
As it uses http requests to send the message to the web service, you need to be online
for notifier to work.
:param cageID_p: identifier for cage, sent in message
:param durationSecs_p: duration that mouse has been in tube, sent in message
:param phoneList_p: tuple of telephone numbers to which the message will be sent
return: nothing
"""
self.URL = 'http://textbelt.com/text'
self.cageID = str (cageID_p)
self.phoneList = phoneList_p
def notify (self, tag, durationSecs, isStuck):
"""
Sends a text message with the given information.
Two types of message can be sent, depending if isStuck is True or False
No timing is done by the AHF_Notifier class, the durations are only for building the text mssg
:param tag: RFID tag of the mouse
:param durationSecs: how long the mouse has been inside the chamber
:param isStuck: boolean signifying if the mouse has been inside the chamber for too long, or has just left the chamber
:return: nothing
"""
if isStuck == True:
alertString = 'Mouse ' + str(tag) + ' has been inside the chamber of cage ' + self.cageID + ' for {:.2f}'.format(durationSecs/60) + ' minutes.'
else:
alertString = 'Mouse ' + str (tag) + ', the erstwhile stuck mouse in cage ' + self.cageID + ' has finally left the chamber after being inside for {:.2f}'.format (durationSecs/60) + ' minutes.'
for i in self.phoneList:
requests.post(self.URL, data={'number': i, 'message': alertString, 'key': 'c67968bac99c6c6a5ab4d0007efa6b876b54e228IoOQ7gTnT6hAJDRKPnt6Cwc9b',})
sleep (2)
print (alertString, ' Messages have been sent.')
if __name__ == '__main__':
import requests
notifier=AHF_Notifier(18, (17789535102, 16043512437,16047904623))
notifier.notify (44, 60, 0)
#7ba7ff8f277d8b7aacf88dd509037a4c41405241