-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcanisms.py
More file actions
executable file
·50 lines (44 loc) · 1.36 KB
/
canisms.py
File metadata and controls
executable file
·50 lines (44 loc) · 1.36 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
#!/usr/bin/python
## can I sms?
## have I sent an sms in the last 5 minutes to a particular recipient regarding this event for this scale?
## inputs:
## eventType
## recipient
## scale_id
import sqlite3 as lite
import os
import sys
import subprocess
import time as t
from datetime import datetime
from dateutil import parser
def main(scale_id,eventType,recipient):
#if len(sys.argv) < 3:
# print "not enough args"
# exit(1)
#scale_id = sys.argv[0]
#eventType = sys.argv[1]
#recipient = str(sys.argv[2])
debug=1
now = datetime.now()
con = lite.connect('/usr/local/CoffeeScale/c16')
con.text_factory = str
con.row_factory = lite.Row
cur=con.cursor()
cur.execute("select MAX(sms_time) as lastsms FROM texts WHERE scale_id=? AND type =? AND recipient=?",(scale_id,eventType,recipient))
row=cur.fetchone()
if str(row[0]) == "None": ## first sms ever
print "Yes"
return True
else :
return False
then = parser.parse(row[0])
if debug: print "last sms to "+recipient+" for "+scale_id+" was "+ str(round( (now - then ).total_seconds() / 60)) +" minutes ago"
### if the last tweet was more than one x ago:
if round( (now - then ).total_seconds() / 60) > 30:
print "Yes"
return True
print "No"
return False
if __name__ == "__main__":
main()