# -*- coding:utf-8 -*- import time import datetime from StockRestPojo import StockRestPojo from dbOperation import dbOperation import db_config from threading import Thread from time import sleep import asyncio async def clacGroupData(dbConfig): db = dbOperation(dbConfig) stockPojoList = db.query_list("select id, code, name, list_date listDate from t_stock_base_info where 1 = 1") for stockPojo in stockPojoList: stockRestPojoList = db.query_list("SELECT id, realTime FROM `data_rt_" + stockPojo['code'].replace(".", "_").lower() + "` where dateOne = '0'") sql = "" for stockRestPojo in stockRestPojoList: datTime = stockRestPojo['realTime'] min_ = time.localtime(datTime).tm_min # 获取分钟 sec_ = time.localtime(datTime).tm_sec # 获取秒数 # 1分钟数据 if sec_ != 0: tempDatTime = datTime + 60 - sec_ stockRestPojo['dateOne'] = str(int(tempDatTime)) else: stockRestPojo['dateOne'] = str(int(datTime)) # 5分钟数据 if sec_ != 0 or min_%5 != 0: tempDatTime = datTime + (5 * 60) - sec_ - (min_%5 * 60) stockRestPojo['dateFive'] = str(int(tempDatTime)) else: stockRestPojo['dateFive'] = str(int(datTime)) # 15分钟数据 if sec_ != 0 or min_%15 != 0: tempDatTime = datTime + (15 * 60) - sec_ - (min_%15 * 60) stockRestPojo['dateFifteen'] = str(int(tempDatTime)) else: stockRestPojo['dateFifteen'] = str(int(datTime)) # 30分钟数据 if sec_ != 0 or min_%30 != 0: tempDatTime = datTime + (30 * 60) - sec_ - (min_%30 * 60) stockRestPojo['dateThirty'] = str(int(tempDatTime)) else: stockRestPojo['dateThirty'] = str(int(datTime)) # 60分钟数据 if sec_ != 0 or min_%60 != 0: tempDatTime = datTime + (60 * 60) - sec_ - (min_%60 * 60) stockRestPojo['dateSixty'] = str(int(tempDatTime)) else: stockRestPojo['dateSixty'] = str(int(datTime)) sql = sql + "update `data_rt_" + stockPojo['code'].replace(".", "_").lower() + "` set dateOne = '" + str(stockRestPojo['dateOne']) + "', dateFive = '" + str(stockRestPojo['dateFive']) + "', dateFifteen = '" + str(stockRestPojo['dateFifteen']) + "', dateThirty = '" + str(stockRestPojo['dateThirty']) + "', dateSixty = '" + str(stockRestPojo['dateSixty']) + "' where id = '" + str(stockRestPojo['id']) + "';" db.update(sql) print("运行完成") db.close async def main(): await asyncio.gather( clacGroupData(db_config.db_gupiao) ) try: #定时任务 每3秒钟触发一次 asyncio.run(main()) except Exception as ee: print("error >>>",ee)