[fix] update data if changed on the same day

This commit is contained in:
n 2022-02-27 13:07:51 +01:00
parent cdf103af68
commit 508774b566
Signed by: n
GPG Key ID: 510227DD6C502CE3
1 changed files with 8 additions and 5 deletions

View File

@ -10,24 +10,27 @@ def main(host='localhost', port=8086, user='root', password='root', dbname='demo
db = InfluxDBClient(host, port, user, password, dbname)
measurements = db.get_list_measurements()
ts = 0
lastdate = 0
laststeps = 0
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
if ts == datetime.datetime.now().timestamp() // 86400 * 86400 + time.timezone:
points = lastentry.get_points('steps')
laststeps = list(points)[0]['last']
if args.verbose:
print("last entry is %s, ts is %s\n" % (lastdate,ts))
print("last entry is %s, ts is %s, number of steps is %s\n" % (lastdate,ts,laststeps))
con = lite.connect(dbfile)
with con:
cur = con.cursor()
cur.execute("SELECT recordedForDate,steps,distanceInMeters,activeTimeInSeconds,calories FROM dailyActivityLog WHERE recordedForDate > %s" %ts)
cur.execute("SELECT recordedForDate,steps,distanceInMeters,activeTimeInSeconds,calories FROM dailyActivityLog WHERE recordedForDate >= %s AND steps > %s" % (ts,laststeps))
while True: