-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollectorFile.py
More file actions
executable file
·37 lines (25 loc) · 948 Bytes
/
collectorFile.py
File metadata and controls
executable file
·37 lines (25 loc) · 948 Bytes
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
#!/opt/bin/python
import ConfigParser
import datetime
config = ConfigParser.RawConfigParser()
config.read('config/collector.cfg')
FILENAME = config.get('file', 'filename')
fileHandle = None
def connectToDatasource(connectionId):
global fileHandle
if fileHandle is None:
fileHandle = open(FILENAME, 'a', 1)
print "opening file"
def writeToDatasource(connectionId, temp=0, date=datetime.datetime.now(), sensorName='unknown'):
connectToDatasource(connectionId)
fileHandle.write(
"INSERT INTO log (value, datetime, fk_sensor) VALUES ({0}, '{1}', '{2}')"
.format(temp, date, sensorName))
def writeToControlDatasource(connectionId, value=0, date=datetime.datetime.now(),):
connectToDatasource()
fileHandle.write(
"INSERT INTO logs_control (value, datetime) VALUES ({0}, '{1}')"
.format(value, date))
def close(connectionId):
global fileHandle
fileHandle.close()