incremental updates

This commit is contained in:
n 2019-05-19 18:43:00 +02:00
parent b370ac5132
commit cfb11ee423
1 changed files with 10 additions and 3 deletions

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."""
db = InfluxDBClient(host, port, user, password, dbname)
lastentry = db.query('SELECT LAST("steps") FROM "steps"')
if lastentry != None:
measurements = db.get_list_measurements()
print(measurements)
if measurements != []:
lastentry = db.query('SELECT LAST("steps") FROM "steps"')
points = lastentry.get_points('steps')
lastdate = list(points)[0]['time']
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))
@ -22,7 +28,7 @@ def main(host='localhost', port=8086, user='root', password='root', dbname='demo
with con:
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:
@ -44,6 +50,7 @@ def main(host='localhost', port=8086, user='root', password='root', dbname='demo
print(data)
db.write_points(data)
db.close()
def parse_args():
"""Parse the args from main."""