Guest User

Untitled

a guest
Nov 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import re
  4. import json
  5. import csv
  6. from datetime import datetime
  7.  
  8. wd_path = os.getcwd()
  9. json_file = os.path.join(wd_path, 'event.json')
  10.  
  11. with open(json_file, 'r') as f:
  12. j_result = json.load(f)
  13.  
  14. csv_path = os.path.join(wd_path, 'event.csv')
  15.  
  16. with open(csv_path, 'w') as f:
  17. writer = csv.writer(f,lineterminator='\n')
  18.  
  19. for rec in j_result['result']:
  20. lst_data = []
  21. # clockを変換(unixtime -> date and time)
  22. s_date = datetime.fromtimestamp(int(rec['clock'])).date()
  23. s_time = datetime.fromtimestamp(int(rec['clock'])).time()
  24. # descriptionの不要部分削除
  25. int_name=re.sub(r'^.*interface|\ |\t','',rec['relatedObject']['description'])
  26. #
  27. if int(rec['value'])==0:
  28. continue ## value=OK skip
  29.  
  30. lst_data.append(s_date)
  31. lst_data.append(s_time)
  32. lst_data.append(rec['relatedObject']['description'])
  33. lst_data.append(rec['hosts'][0]['name'])
  34. lst_data.append(int_name)
  35. lst_data.append(rec['value'])
  36. writer.writerow(lst_data)
Add Comment
Please, Sign In to add comment