main.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from common.ext_database import init_db
  2. from common.utils import save_json
  3. from common.logger import logger
  4. from util.riil_api import RiilApi
  5. class Main:
  6. def __init__(self):
  7. init_db()
  8. self.api = RiilApi()
  9. def get_events(self):
  10. all_unaccepted_event_list = []
  11. all_accepted_event_list = []
  12. res_id_set = set()
  13. # for i in range(1, 26):
  14. # unaccepted_event_list = self.api.query_event_list("unaccepted_event_view", pageIndex=i)
  15. # all_unaccepted_event_list.extend(unaccepted_event_list.get('eventList'))
  16. # save_json(all_unaccepted_event_list, "result/event/unaccepted_event_list.json")
  17. for i in range(1, 2):
  18. unaccepted_event_list = self.api.query_event_list("accepted_event_view", pageIndex=i)
  19. all_accepted_event_list.extend(unaccepted_event_list.get('eventList'))
  20. save_json(all_accepted_event_list, "result/event/accepted_event_list.json")
  21. # event_list = self.api.get_log_alarm_list()
  22. # save_json(event_list, "result/event/event_list.json")
  23. for i in all_accepted_event_list:
  24. res_id_set.add(i.get('resId'))
  25. all_res_list = []
  26. for res_id in res_id_set:
  27. res = self.api.get_res_instance_by_id(res_id)
  28. all_res_list.append(res)
  29. save_json(all_res_list, "result/res/res.json")
  30. def get_resources(self):
  31. # 获取主资源列表
  32. page_index = 1
  33. res_list = []
  34. while True:
  35. res_dict = self.api.get_res_list('00')
  36. if page_index >= res_dict.get('totalPage'):
  37. break
  38. page_index += 1
  39. res = res_dict.get('resList', [])
  40. res_list.extend(res)
  41. save_json(res_list, "result/res/res_list.json")
  42. def get_ip_all_segment(self):
  43. res = self.api.get_all_subnet_info()
  44. save_json(res, "result/ip/ip_all_segment.json")
  45. res_location = self.api.get_ipmac_location_list()
  46. def get_room(self):
  47. res = self.api.get_all_room()
  48. save_json(res, "result/room/room_list.json")
  49. event_from_room = []
  50. for room in res.get("roomVOList", []):
  51. room_id = room.get("id")
  52. res = self.api.get_element_by_room_id(room_id)
  53. event_from_room.extend(res.get('elementPojoList', []))
  54. save_json(event_from_room, "result/room/event_from_room.json")
  55. def run(self):
  56. # 运行
  57. self.get_events()
  58. # self.get_resources()
  59. # self.get_ip_all_segment()
  60. # self.get_room()
  61. if __name__ == '__main__':
  62. main = Main()
  63. main.run()