-
Notifications
You must be signed in to change notification settings - Fork 0
/
clanless.py
77 lines (73 loc) · 3.54 KB
/
clanless.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import requests
import pandas as pd
token = ""
headers = {'authorization': 'Bearer ' +token,'Accept': 'application/json' }
tag = ""
# Manually input a player tag
# while True:
# tag = input("Enter the player tag: ")
# tag = tag.replace("#","")
# response_json = requests.get('https://api.clashofclans.com/v1/players/%23'+ tag, headers=headers).json()
# try:
# print(response_json['clan']['name'])
# except KeyError:
# print("Not in a clan")
# print(response_json['name'])
# print(response_json['warStars'], 'war stars')
# if response_json['townHallLevel'] >= 13:
# print('Town hall', response_json['townHallLevel'])
# else:
# print('Low level Town hall', response_json['townHallLevel'])
# if response_json['clanCapitalContributions'] == 0:
# print('0 clan capital contributions')
# elif response_json['clanCapitalContributions'] < 100000:
# print('Bad clan capital contributions:', response_json['clanCapitalContributions'])
# else:
# print('Clan capital contributions:', response_json['clanCapitalContributions'])
# Get random sample of n clanless players
file = '2024-03.csv'
n = 1000
df = pd.read_csv(file)
df_random = df.sample(n=n)
for i in range(len(df_random)):
tag = df_random.iloc[i]['tag']
tag = tag.replace("#","")
response_json = requests.get('https://api.clashofclans.com/v1/players/%23'+ tag, headers=headers).json()
try:
clan = response_json['clan']['name']
except KeyError:
#print('\n' * 5)
try:
name = response_json['name']
#print("Not in a clan")
if response_json['townHallLevel'] >= 15 and response_json['clanCapitalContributions'] != 0 and response_json['warStars'] > 1000 and response_json['bestTrophies'] > 5000:
print(name)
print('#'+tag)
print(response_json['warStars'], 'war stars')
print('Town hall', response_json['townHallLevel'])
try:
print(response_json['heroes'][0]['name'], response_json['heroes'][0]['level'])
print(response_json['heroes'][1]['name'], response_json['heroes'][1]['level'])
print(response_json['heroes'][2]['name'], response_json['heroes'][2]['level'])
print(response_json['heroes'][4]['name'], response_json['heroes'][4]['level'])
except:
print(response_json['heroes'][3]['name'], response_json['heroes'][3]['level'])
#else:
# print('Low level Town hall', response_json['townHallLevel'])
print(response_json['attackWins'], 'attack wins')
print(response_json['defenseWins'], 'defense wins')
print(response_json['bestTrophies'], 'best trophies')
try:
print(response_json['legendStatistics']['previousSeason']['trophies'], 'best trophies last season')
except:
pass
if response_json['clanCapitalContributions'] == 0:
print('0 clan capital contributions')
elif response_json['clanCapitalContributions'] < 100000:
print('Bad clan capital contributions:', response_json['clanCapitalContributions'])
else:
print('Clan capital contributions:', response_json['clanCapitalContributions'])
print('\n')
except KeyError:
#print('Banned/Unknown')
pass