Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import json
  2. import os
  3. import xlwt
  4. import threading
  5.  
  6. def json_to_xls(i):
  7. wb = xlwt.Workbook()
  8. ws = wb.add_sheet('sheet 1')
  9. ws.write(0, 0, 'Type:')
  10. ws.write(0, 1, 'Project Id:')
  11.  
  12. with open(i, 'r', encoding='utf-8') as fh:
  13. data = json.load(fh)
  14.  
  15. l = 1
  16. for d in data:
  17. ws.write(l, 0, d.get('type'))
  18. ws.write(l, 1, d.get('project_id'))
  19. l += 1
  20.  
  21. wb.save(i + '.xls')
  22.  
  23. files = os.listdir()
  24. thread_list = []
  25. value = 0
  26.  
  27. thread_list = []
  28. for i in files:
  29. json_file = i.endswith('.json')
  30. if json_file == True:
  31. t = threading.Thread(target = json_to_xls, name = value, args = i)
  32. value += 1
  33. t.start()
  34. thread_list.append(t)
  35. print(i)
  36. converter_json(i)
  37.  
  38. for t in thread_list:
  39. t.join()
  40.  
  41. TypeError: json_to_xls() takes 1 positional argument but 21 were given
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement