Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from time import sleep
- clan_counter = 0
- opponent_counter = 0
- error_counter = 0
- clan_attack = 0
- clan_stars = 0
- clan_array = {}
- clan_order = {}
- opponent_array = {}
- while True:
- with open('api.json', 'r', encoding="utf8") as coc_file:
- x = json.load(coc_file)
- for member in x['clan']['members']:
- try:
- if member['name'] not in clan_array:
- clan_array[member['name']] = member['attacks'][0]['stars']
- clan_order[clan_counter] = member['name']
- clan_counter += 1
- except KeyError:
- error_counter += 1
- with open('data.dat', 'w', encoding="utf8") as data_file:
- for i in range(len(clan_order)):
- data_file.write(str(clan_array[clan_order[i]]) + "\n")
- sleep(1)
- import json
- counter = 0
- data = []
- stars_json = None
- def build_json(data, counter):
- x = None
- stars_json = 0
- if len(data) > 0:
- for i in range(counter):
- stars_json += int(data[i])
- x = {"attacks": counter, "stars": stars_json}
- return x
- with open('counter.txt', 'r') as counter_source:
- counter_temp = counter_source.read()
- counter = int(counter_temp)
- while counter != 16:
- with open('data.dat', 'r') as data_file:
- for line in data_file:
- currentPlace = line[:-1]
- data.append(currentPlace)
- try:
- stars_json = build_json(data, counter)
- except IndexError:
- print('Atak się jeszcze nie odbył')
- counter -= 1
- with open('data.json', 'w') as json_file:
- json_file.write(json.dumps(stars_json))
- with open('counter.txt', 'w') as counter_file:
- counter_file.write(str(counter))
- if input() == 'p':
- counter += 1
- data.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement