pylint fixes
This commit is contained in:
parent
508774b566
commit
7f21244c01
1 changed files with 32 additions and 29 deletions
|
@ -1,60 +1,65 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from influxdb import InfluxDBClient
|
|
||||||
|
"""Export Pacer data to InfluxDB"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import sqlite3 as lite
|
import sqlite3 as lite
|
||||||
import argparse
|
import argparse
|
||||||
|
from influxdb import InfluxDBClient
|
||||||
|
|
||||||
def main(host='localhost', port=8086, user='root', password='root', dbname='demo', dbfile='demo.db'):
|
def main(args):
|
||||||
"""Instantiate the connection to the InfluxDB client."""
|
"""Instantiate the connection to the InfluxDB client."""
|
||||||
|
|
||||||
db = InfluxDBClient(host, port, user, password, dbname)
|
influx_db = InfluxDBClient(args.host, args.port, args.user, args.password, args.dbname)
|
||||||
measurements = db.get_list_measurements()
|
measurementime_stamp = influx_db.get_list_measurementime_stamp()
|
||||||
ts = 0
|
time_stamp = 0
|
||||||
lastdate = 0
|
lastdate = 0
|
||||||
laststeps = 0
|
lastime_stampteps = 0
|
||||||
if measurements != []:
|
if measurementime_stamp != []:
|
||||||
lastentry = db.query('SELECT LAST("steps") FROM "steps"')
|
lastentry = influx_db.query('SELECT LAST("steps") FROM "steps"')
|
||||||
|
|
||||||
points = lastentry.get_points('steps')
|
pointime_stamp = lastentry.get_pointime_stamp('steps')
|
||||||
lastdate = list(points)[0]['time']
|
lastdate = list(pointime_stamp)[0]['time']
|
||||||
ts = time.mktime(datetime.datetime.strptime(lastdate, '%Y-%m-%dT%H:%M:%SZ').timetuple())
|
time_stamp = time.mktime(datetime.datetime.strptime(lastdate, '%Y-%m-%dT%H:%M:%SZ')
|
||||||
if ts == datetime.datetime.now().timestamp() // 86400 * 86400 + time.timezone:
|
.timetuple())
|
||||||
points = lastentry.get_points('steps')
|
if time_stamp == datetime.datetime.now().timestamp() // 86400 * 86400 + time.timezone:
|
||||||
laststeps = list(points)[0]['last']
|
pointime_stamp = lastentry.get_pointime_stamp('steps')
|
||||||
|
lastime_stampteps = list(pointime_stamp)[0]['last']
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("last entry is %s, ts is %s, number of steps is %s\n" % (lastdate,ts,laststeps))
|
print(f'last entry is {lastdate}, time_stamp is {time_stamp}, \
|
||||||
|
number of steps is {lastime_stampteps}\n')
|
||||||
|
|
||||||
con = lite.connect(dbfile)
|
con = lite.connect(args.dbfile)
|
||||||
with con:
|
with con:
|
||||||
|
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("SELECT recordedForDate,steps,distanceInMeters,activeTimeInSeconds,calories FROM dailyActivityLog WHERE recordedForDate >= %s AND steps > %s" % (ts,laststeps))
|
cur.execute(f'SELECT recordedForDate,steps,distanceInMeters,activeTimeInSeconds,calories \
|
||||||
|
FROM dailyActivityLog \
|
||||||
|
WHERE recordedForDate >= {time_stamp} AND steps > {lastime_stampteps}')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
if row == None:
|
if row is None:
|
||||||
break
|
break
|
||||||
mytime = datetime.datetime.fromtimestamp(row[0]).strftime('%Y-%m-%dT%H:%M:%SZ')
|
mytime = datetime.datetime.fromtimestamp(row[0]).strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
data = [
|
data = [{"measurement":"steps",
|
||||||
{"measurement":"steps",
|
|
||||||
"time":mytime,
|
"time":mytime,
|
||||||
"fields": {
|
"fields": {
|
||||||
"steps":row[1],
|
"steps":row[1],
|
||||||
"distanceInMeters":row[2],
|
"distanceInMeters":row[2],
|
||||||
"activeTimeInSeconds":row[3],
|
"activeTimeInSeconds":row[3],
|
||||||
"calories":row[4]
|
"calories":row[4]
|
||||||
}
|
}
|
||||||
}
|
}]
|
||||||
]
|
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("writing data for %s" % (mytime))
|
print(f'writing data for {mytime}')
|
||||||
|
|
||||||
db.write_points(data)
|
influx_db.write_pointime_stamp(data)
|
||||||
db.close()
|
influx_db.close()
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
"""Parse the args from main."""
|
"""Parse the args from main."""
|
||||||
|
@ -80,7 +85,5 @@ def parse_args():
|
||||||
help='sqlite (pacer) database name')
|
help='sqlite (pacer) database name')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parse_args()
|
main(parse_args())
|
||||||
main(host=args.host, port=args.port, user=args.user, password=args.password, dbname=args.dbname, dbfile=args.dbfile)
|
|
||||||
|
|
Loading…
Reference in a new issue