main.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import datetime
  2. import json,pymysql
  3. import os
  4. import time,re
  5. from MyUtils.MysqlUtils import MysqlUtils
  6. import pytz
  7. import multiprocessing
  8. SELETE_SQL = "SELECT id,project_id,infos from object_data_object_infos WHERE id LIKE '%s' or id LIKE '%s'"
  9. def datetime_now():
  10. # datetime_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  11. #容器时间
  12. # tz = pytz.timezone('Asia/Shanghai') # 东八区
  13. datetime_now = datetime.datetime.fromtimestamp(int(time.time()),
  14. pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S')
  15. return datetime_now
  16. with open("config.json", "r") as f:
  17. data = json.load(f)
  18. buildings = data["buildings"]
  19. mysql = data["mysql"]
  20. conn = pymysql.connect(**mysql)
  21. mysql_cur = conn.cursor()
  22. sql = SELETE_SQL%("Eq%","Sp%")
  23. mysql_cur.execute(sql)
  24. datas = mysql_cur.fetchall()
  25. for i in datas:
  26. id = i[0]
  27. project_id = i[1]
  28. infos = i[2]
  29. infos = json.loads(infos)
  30. infos = dict(infos)
  31. for info in infos.items():
  32. #筛选值存在切key不为RoomLocalName的info
  33. if info[1] and info[0] != "RoomLocalName":
  34. #筛选字符串中只有一个“-”
  35. if len(re.findall("-",str(info[1]))) == 1:
  36. #筛选“-”后为数字的info
  37. if str(info[1]).split("-")[1].isdigit() == True:
  38. obj = info[0]
  39. value = info[1]
  40. meter = str(info[1]).split("-")[0]
  41. funcid = str(info[1]).split("-")[1]
  42. print(id,project_id,obj,meter,funcid)
  43. aa = project_id+";"+id+";"+obj+";"+meter+";"+funcid
  44. with open("data.txt", "a+",encoding="utf-8") as file:
  45. file.write(aa)
  46. file.write("\n")
  47. mysql_cur.close()
  48. conn.close()