-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessLog.py
More file actions
70 lines (63 loc) · 2.54 KB
/
MessLog.py
File metadata and controls
70 lines (63 loc) · 2.54 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
#!/usr/bin/python3
#import time
from time import strftime, localtime
class MessLog():
''' Class to get last message time from file to see if a new message should be sent
'''
def __init__(self, dirPrepend = '', filename = ''):
''' Initalize object with the directory prepend and name of file
'''
self.dirPrepend = dirPrepend
self.filename = filename
self.setLogFile(dirPrepend = self.dirPrepend, filename = self.filename)
def readLogTime(self):
''' Method to read the log time then return the timestamp
'''
try:
f = open(self.filename, 'r')
sendtime = float(f.read()) + 1200
f.close()
except IOError:
sendtime = 0
except:
sendtime = -1
# return the timestamp
return sendtime
def writeLogTime(self, ts):
''' Method to write new timestamp to log file
'''
try:
f = open(self.filename, 'w')
f.write(str(ts))
f.close()
except:
pass
def writeLogFile(self, message):
''' Method to write debug to log file. All in variables must be strings
'''
try:
f = open(self.filename, 'a')
f.write('Log Time: ' + strftime("%H:%M:%S", localtime()) + ' - ')
f.write(message)
f.write('\n')
f.close()
except:
print('Error making Log file')
def writeDebugFile(self, lasttimestamp, newtimestamp, messagereq, debugResp1='', debugResp2='', debugResp3=''):
''' Method to write debug to log file. All in variables must be strings
'''
try:
f = open(self.debugfile, 'a')
f.write('Log Time: ' + strftime("%H:%M:%S", localtime()) + '\r\n')
f.write('Message Requested: ' + messagereq + '\r\n')
f.write('Next Message Send Timestamp: ' + lasttimestamp + '\r\n')
f.write('Current Timestamp: ' + newtimestamp + '\r\n')
f.write(debugResp1 + '\r\n')
f.write(debugResp2 + '\r\n')
f.write(debugResp3 + '\r\n\r\n')
f.close()
except:
print('Error making Debug file')
def setLogFile(self, dirPrepend = '', filename = ''):
self.filename = dirPrepend + strftime("%b-%d-%y", localtime()) + "-" + filename + '.log'
self.debugfile = dirPrepend + strftime("%b-%d-%y", localtime()) + 'debug-SMS-trigger' + '.log'