Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import json
  2. from time import sleep
  3.  
  4. clan_counter = 0
  5. opponent_counter = 0
  6. error_counter = 0
  7.  
  8. clan_attack = 0
  9. clan_stars = 0
  10.  
  11. clan_array = {}
  12. clan_order = {}
  13. opponent_array = {}
  14.  
  15. while True:
  16.  
  17. with open('api.json', 'r', encoding="utf8") as coc_file:
  18. x = json.load(coc_file)
  19.  
  20. for member in x['clan']['members']:
  21. try:
  22. if member['name'] not in clan_array:
  23. clan_array[member['name']] = member['attacks'][0]['stars']
  24. clan_order[clan_counter] = member['name']
  25. clan_counter += 1
  26. except KeyError:
  27. error_counter += 1
  28.  
  29. with open('data.dat', 'w', encoding="utf8") as data_file:
  30. for i in range(len(clan_order)):
  31. data_file.write(str(clan_array[clan_order[i]]) + "\n")
  32.  
  33. sleep(1)
  34.  
  35.  
  36. import json
  37.  
  38. counter = 0
  39. data = []
  40.  
  41. stars_json = None
  42.  
  43.  
  44. def build_json(data, counter):
  45. x = None
  46. stars_json = 0
  47. if len(data) > 0:
  48. for i in range(counter):
  49. stars_json += int(data[i])
  50. x = {"attacks": counter, "stars": stars_json}
  51. return x
  52.  
  53.  
  54. with open('counter.txt', 'r') as counter_source:
  55. counter_temp = counter_source.read()
  56. counter = int(counter_temp)
  57.  
  58. while counter != 16:
  59.  
  60. with open('data.dat', 'r') as data_file:
  61. for line in data_file:
  62. currentPlace = line[:-1]
  63. data.append(currentPlace)
  64.  
  65. try:
  66. stars_json = build_json(data, counter)
  67. except IndexError:
  68. print('Atak się jeszcze nie odbył')
  69. counter -= 1
  70.  
  71. with open('data.json', 'w') as json_file:
  72. json_file.write(json.dumps(stars_json))
  73.  
  74. with open('counter.txt', 'w') as counter_file:
  75. counter_file.write(str(counter))
  76.  
  77. if input() == 'p':
  78. counter += 1
  79. data.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement