__author__ = 'lmstack' #coding=utf-8 import os import datetime import pandas as pd from LIB.BACKEND import DBManager, Log from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import time, datetime import dateutil.relativedelta import traceback from LIB.MIDDLE.CellStateEstimation.Common import log from LIB.MIDDLE.SaftyCenter.Offline import offline_alarm from urllib import parse import pymysql from LIB.BACKEND import DBManager if __name__ == "__main__": # 日志配置 now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_") log_path = 'log/' + now_str if not os.path.exists(log_path): os.makedirs(log_path) log = Log.Mylog(log_name='saftyCenter_offline', log_level = 'info') log.set_file_hl(file_name='{}/info.log'.format(log_path), log_level='info', size=1024* 1024 * 100) log.set_file_hl(file_name='{}/error.log'.format(log_path), log_level='error', size=1024* 1024 * 100) logger = log.get_logger() logger.info("pid is {}".format(os.getpid())) try: # 算法参数 host='172.16.121.236' port=3306 db='fastfun' user='readonly' password='Fast1234' db_iotp_engine = create_engine( "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format( user, parse.quote_plus(password), host, port, db )) host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com' port=3306 db='qx_cas' user='qx_algo_rw' password='qx@123456' db_qxcas_engine = create_engine( "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format( user, parse.quote_plus(password), host, port, db )) host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com' port=3306 db='qixiang_manage' user='qx_query' password='@Qx_query' conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db) cursor = conn.cursor() cursor.execute("select qrcode from py_battery where status=3") res = cursor.fetchall() ignore_sns = pd.DataFrame(res, columns=['sn'])['sn'].tolist() logger.info("pid-{} START!".format(os.getpid())) offline_alarm.offline_alarm(db_iotp_engine, db_qxcas_engine, ignore_sns) logger.info("pid-{} DONE!".format(os.getpid())) except: logger.error(traceback.format_exc) logger.error("任务运行错误", exc_info=True) db_iotp_engine.dispose() db_qxcas_engine.dispose() cursor.close() conn.close