import pandas as pd
import datetime
start = datetime.datetime.now()
conn = psycopg2.connect()
df_com_info = pd.read_sql_query(com_info_sql, conn)
def decorator(time_diff=3600):
"""
当距离上次查询时间大于3600s时重新查询数据库
time_diff:距离上次查询时间秒(单位s)
"""
def log_time(func):
# 参数是原函数参数,返回值是原函数返回值result
def wrapper(*args, **kwargs):
global start, df_com_info
time_cost = (datetime.datetime.now()- start).seconds
if time_cost > time_diff:
result = func(*args, **kwargs)
df_com_info = result
start = datetime.datetime.now()
else:
result = df_com_info
log_str = """查询数据表:{}, 距离上次查询时间差:{}, 获取数:{} """.format(func.__name__, end - start,
|