4
import adeitools as adei
5
from adeitools import DEBUG_
6
import simplejson as json
9
deviceConfig = '../hatpro.ini'
10
serverConfig = '../server.ini'
12
def parseConfig(sensor_):
13
# read server and sensor info from configuration
14
# find sensor and group, then initialize adei server
15
# there should be only one matched sensor, check?
17
config = ConfigParser.ConfigParser()
18
config.read(deviceConfig)
19
config.read(serverConfig)
21
sensors = [dict(config._sections[a])
22
for a in config.sections() if re.match('^sensor\d+', a)]
24
servers = [dict(config._sections[a])
25
for a in config.sections() if re.match('^server', a)]
28
sensor = [s for s in sensors if s['id'] == sensor_ ]
31
print "sensor id %s is not found in configuration" % sensor_
34
print "sensor id %s found in configuration" % sensor_
37
server = [ s for s in servers
38
if s['__name__'] == sensor['server'] ]
39
group = sensor['group']
41
return (server[0], group)
44
class adeiReader(adei.adeiReader):
45
def dostuff(self, group_, sensor_, date_):
48
stamp00 = self.groupLastStamp(group_)
49
stamp0 = self.groupLastDayStamp(group_)
53
'2d': stamp0 - 86400*2
55
filestamp = stampOptions[date_]
58
filename = "../cache/%s.%s.%s.json" % (
59
device_, sensor_, filestamp)
64
with open(filename, 'r') as f:
65
oldstamp = json.loads(f.read())['time'][-1]
66
if oldstamp > stamp0 and oldstamp < stamp00:
68
print 'update ? ', stamp0, oldstamp, stamp00, update
75
return (filestamp, update)