incremental updates

This commit is contained in:
n 2019-05-19 18:43:00 +02:00
parent b370ac5132
commit cfb11ee423

View file

@ -10,11 +10,17 @@ def main(host='localhost', port=8086, user='root', password='root', dbname='demo
"""Instantiate the connection to the InfluxDB client.""" """Instantiate the connection to the InfluxDB client."""
db = InfluxDBClient(host, port, user, password, dbname) db = InfluxDBClient(host, port, user, password, dbname)
measurements = db.get_list_measurements()
print(measurements)
if measurements != []:
lastentry = db.query('SELECT LAST("steps") FROM "steps"') lastentry = db.query('SELECT LAST("steps") FROM "steps"')
if lastentry != None:
points = lastentry.get_points('steps') points = lastentry.get_points('steps')
lastdate = list(points)[0]['time'] lastdate = list(points)[0]['time']
ts = time.mktime(datetime.datetime.strptime(lastdate, '%Y-%m-%dT%H:%M:%SZ').timetuple()) ts = time.mktime(datetime.datetime.strptime(lastdate, '%Y-%m-%dT%H:%M:%SZ').timetuple())
else:
ts=0
lastdate=0
print("last entry is %s, ts is %s" % (lastdate,ts)) print("last entry is %s, ts is %s" % (lastdate,ts))
@ -22,7 +28,7 @@ def main(host='localhost', port=8086, user='root', password='root', dbname='demo
with con: with con:
cur = con.cursor() cur = con.cursor()
cur.execute("SELECT recordedForDate,steps,distanceInMeters,activeTimeInSeconds,calories FROM dailyActivityLog WHERE recordedForDate > %s ORDER BY recordedForDate DESC" %ts) cur.execute("SELECT recordedForDate,steps,distanceInMeters,activeTimeInSeconds,calories FROM dailyActivityLog WHERE recordedForDate > %s" %ts)
while True: while True:
@ -44,6 +50,7 @@ def main(host='localhost', port=8086, user='root', password='root', dbname='demo
print(data) print(data)
db.write_points(data) db.write_points(data)
db.close()
def parse_args(): def parse_args():
"""Parse the args from main.""" """Parse the args from main."""