[fix] update data if changed on the same day
This commit is contained in:
parent
cdf103af68
commit
508774b566
1 changed files with 8 additions and 5 deletions
|
@ -10,24 +10,27 @@ def main(host='localhost', port=8086, user='root', password='root', dbname='demo
|
||||||
|
|
||||||
db = InfluxDBClient(host, port, user, password, dbname)
|
db = InfluxDBClient(host, port, user, password, dbname)
|
||||||
measurements = db.get_list_measurements()
|
measurements = db.get_list_measurements()
|
||||||
|
ts = 0
|
||||||
|
lastdate = 0
|
||||||
|
laststeps = 0
|
||||||
if measurements != []:
|
if measurements != []:
|
||||||
lastentry = db.query('SELECT LAST("steps") FROM "steps"')
|
lastentry = db.query('SELECT LAST("steps") FROM "steps"')
|
||||||
|
|
||||||
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:
|
if ts == datetime.datetime.now().timestamp() // 86400 * 86400 + time.timezone:
|
||||||
ts=0
|
points = lastentry.get_points('steps')
|
||||||
lastdate=0
|
laststeps = list(points)[0]['last']
|
||||||
|
|
||||||
if args.verbose:
|
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)
|
con = lite.connect(dbfile)
|
||||||
with con:
|
with con:
|
||||||
|
|
||||||
cur = con.cursor()
|
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:
|
while True:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue