diff --git a/pacer2influxdb.py b/pacer2influxdb.py index b3f2f44..d6ba334 100755 --- a/pacer2influxdb.py +++ b/pacer2influxdb.py @@ -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."""