__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_sta from urllib import parse import pymysql from LIB.BACKEND import DBManager if __name__ == "__main__": # 更新sn列表 host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com' port=3306 db='qixiang_oss' user='qx_algo_rw' password='qx@123456' conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db) cursor = conn.cursor() cursor.execute("select sn, imei, add_time from app_device where status in (1,2,3)") res = cursor.fetchall() df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time']) df_sn = df_sn.reset_index(drop=True) cursor.close() conn.close(); df_sn['factory'] = '骑享' db = 'qx_cas' conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db) cursor = conn.cursor() cursor.execute("select sn, factory from sn_list") res = cursor.fetchall() df_sn2 = pd.DataFrame(res, columns=['sn', 'factory']) df_sn2['imei'] = "" df_sn2['factory'] = '金茂换电' df_sn = pd.concat([df_sn, df_sn2], axis=0) df_sn = df_sn.reset_index(drop=True) # 日志配置 now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_") log_path = 'log_sta/' + now_str if not os.path.exists(log_path): os.makedirs(log_path) log = Log.Mylog(log_name='saftyCenter_offlinesta', 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 )) db = 'safety_platform' conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db) db_sp_engine = create_engine( "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format( user, parse.quote_plus(password), host, port, db )) logger.info("pid-{} START!".format(os.getpid())) offline_alarm_sta.offline_alarm_sta(df_sn, db_iotp_engine, db_qxcas_engine, conn, db_sp_engine) 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() conn.close()