import datetime import json,pymysql import os import time,re from MyUtils.MysqlUtils import MysqlUtils import pytz import multiprocessing SELETE_SQL = "SELECT id,project_id,infos from object_data_object_infos WHERE id LIKE '%s' or id LIKE '%s'" def datetime_now(): # datetime_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S") #容器时间 # tz = pytz.timezone('Asia/Shanghai') # 东八区 datetime_now = datetime.datetime.fromtimestamp(int(time.time()), pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S') return datetime_now with open("config.json", "r") as f: data = json.load(f) buildings = data["buildings"] mysql = data["mysql"] conn = pymysql.connect(**mysql) mysql_cur = conn.cursor() sql = SELETE_SQL%("Eq%","Sp%") mysql_cur.execute(sql) datas = mysql_cur.fetchall() for i in datas: id = i[0] project_id = i[1] infos = i[2] infos = json.loads(infos) infos = dict(infos) for info in infos.items(): #筛选值存在切key不为RoomLocalName的info if info[1] and info[0] != "RoomLocalName": #筛选字符串中只有一个“-” if len(re.findall("-",str(info[1]))) == 1: #筛选“-”后为数字的info if str(info[1]).split("-")[1].isdigit() == True: obj = info[0] value = info[1] meter = str(info[1]).split("-")[0] funcid = str(info[1]).split("-")[1] print(id,project_id,obj,meter,funcid) aa = project_id+";"+id+";"+obj+";"+meter+";"+funcid with open("data.txt", "a+",encoding="utf-8") as file: file.write(aa) file.write("\n") mysql_cur.close() conn.close()