Gooday,
In the controler the function works correctly. But as a task, it gives an error about Json not beeing able to deal with datetime.
any suggestion would be appreciated :)
here is the error : TypeError: datetime.datetime(2020, 6, 16, 5, 17, 49) is not JSON serializable
here is the code:
#reload(sys)
#sys.setdefaultencoding('utf-8')
import sys
import os
import time
import datetime
import sqlite3
#
#------------------------------------------------------------------------------
def pump_most_recent():
state = 'unknown'
try:
conn=sqlite3.connect('z:/alarm.sqlite')
except sqlite3.Error as err:
state = err # ='connexion impossible'
else:
state = 'connection ok'
# last entry in the local storage is kept in the acue table, have to get this in order to query the prod databases
k = db(db.acue).select(db.acue.dstd2) # get the row
l = k[0].dstd2 # get the date of interest
curs=conn.cursor()
rows = curs.execute("select * from log_txt where date > ?", (l,)).fetchall()
curs.close()
conn.close()
#
for row in rows:
a = datetime.datetime.strptime(row[1],'%Y-%m-%d : %H:%M:%S') # date avec le temps
b = row[2]
c = row[3]
d = row[4]
e = row[5]
f = row[6]
g = row[7]
h = row[8]
i = row[9]
j = row[10]
#
db.alogs.insert(quand=a,etat=b,zone1=c,zone2=d,zone3=e,zone4=f,zone5=g,zone6=h,zone7=i,note=j)
finally:
return locals()
#
#-------------------------------------------------------------------------------
#
def acue_src_dst_update():
#
z = acue_src_dst_show()
a = z.get('a')
b = z.get('b')
c = z.get('c')
d = z.get('d')
#
db.acue.truncate()
db.acue.insert(srcd1=a,srcd2=b,dstd1=c, dstd2=d)
acue_after_update = db(db.acue).select()
#
return locals()
#------------------------------------------------------------------------------------------------------
from gluon.scheduler import Scheduler
Scheduler(db,dict(sync_data=pump_most_recent,sync_dates=acue_src_dst_update))