Browse Source

update 电池信号

su-lmstack 3 years ago
parent
commit
d1b9ba62fa
1 changed files with 14 additions and 9 deletions
  1. 14 9
      LIB/FRONTEND/SignalMonitor/main.py

+ 14 - 9
LIB/FRONTEND/SignalMonitor/main.py

@@ -9,6 +9,8 @@ from sqlalchemy.orm import sessionmaker
 import time, datetime
 import traceback
 
+from urllib import parse
+
 dbManager = DBManager.DBManager()
 if __name__ == "__main__":
     try:
@@ -16,15 +18,16 @@ if __name__ == "__main__":
         host = 'rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
         port = 3306
         user = 'qx_cas'
-        password = 'Qx@123456'
+        password = parse.quote_plus('Qx@123456')
         database = 'qx_cas'
 
         db_engine = create_engine(
             "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
                 user, password, host, port, database
             ))
-
-        db_engine = create_engine("mysql+pymysql://qx_cas:Qx@123456@rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com/qx_cas?charset=utf8")
+        print("mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, password, host, port, database
+            ))
         DbSession = sessionmaker(bind=db_engine)
         
         # 日志配置
@@ -81,13 +84,15 @@ if __name__ == "__main__":
                 st = st + datetime.timedelta(hours=cal_period)
 
             # 数据入库
-            df_tosql = df_last_state.copy()
-            df_tosql.columns = ['sn', 'current', 'time_stamp', 'pack_state', 'line_state']
-            df_tosql.to_sql("bms_last_data_day",con=db_engine, if_exists="append",index=False)
+                df_tosql = df_last_state.copy()
+                df_tosql.columns = ['sn', 'current', 'time_stamp', 'pack_state', 'line_state']
+                df_tosql.to_sql("bms_last_data_day",con=db_engine, if_exists="append",index=False)
+                print(df_tosql)
 
-            df_tosql = df_last_state.copy()
-            df_tosql.columns = ['sn', 'time_stamp', 'pack_state', 'line_state']
-            df_tosql.to_sql("gps_last_data_day",con=db_engine, if_exists="append",index=False)
+                df_tosql = df_last_state_gps.copy()
+                df_tosql.columns = ['sn', 'time_stamp', 'pack_state', 'line_state']
+                df_tosql.to_sql("gps_last_data_day",con=db_engine, if_exists="append",index=False)
+                print(df_tosql)
 
             logger.info("{} {} Success!".format(sn, str(st)))
     except Exception as e: