extract_uuid.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import re
  2. import pandas as pd
  3. import pickle
  4. def save(object_to_save, path):
  5. '''
  6. 保存对象
  7. @Arugs:
  8. object_to_save: 需要保存的对象
  9. @Return:
  10. 保存的路径
  11. '''
  12. with open(path, 'wb') as f:
  13. pickle.dump(object_to_save, f)
  14. def extract_uuid_from_log():
  15. list_files = [
  16. "/data/python/flow_init_log/flow_init_2022-06-02.log",
  17. "/data/python/flow_init_log/flow_init_2022-06-03.log",
  18. "/data/python/flow_init_log/flow_init_2022-06-04.log",
  19. "/data/python/flow_init_log/flow_init_2022-06-05.log",
  20. "/data/python/flow_init.log"
  21. ]
  22. list_uuid = []
  23. _regrex = "delete\s+(?P<tablename>bxkc[^\s]+)\s+.*ID='(?P<uuid>.+)'"
  24. for _file in list_files:
  25. with open(_file,"r",encoding="utf8") as f:
  26. while 1:
  27. _line = f.readline()
  28. if not _line:
  29. break
  30. _match = re.search(_regrex,_line)
  31. if _match is not None:
  32. _uuid = _match.groupdict().get("uuid")
  33. tablename = _match.groupdict().get("tablename")
  34. if _uuid is not None:
  35. list_uuid.append({"uuid":_uuid,"tablename":tablename})
  36. df_data = {"uuid":[],
  37. "tablename":[]}
  38. for _data in list_uuid:
  39. for k,v in df_data.items():
  40. v.append(_data.get(k))
  41. save(df_data,"uuid.pk")
  42. if __name__ == '__main__':
  43. extract_uuid_from_log()