-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
111 lines (89 loc) · 3.95 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from inspect import _void
import os
import json
import requests
# PlayerTags
# 2G00P0QJU Diego
# Y9QPJP8 Gerardo
# RPY9QYU0J Iker
def clearConsole():
"""Borra la consola independientemente del SO"""
command = 'clear'
if os.name in ('nt', 'dos'):
command = 'cls'
os.system(command)
class ClashRoyale:
def __init__(self, tag):
self.tag = tag
self.my_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiIsImtpZCI6IjI4YTMxOGY3LTAwMDAtYTFlYi03ZmExLTJjNzQzM2M2Y2NhNSJ9.eyJpc3MiOiJzdXBlcmNlbGwiLCJhdWQiOiJzdXBlcmNlbGw6Z2FtZWFwaSIsImp0aSI6ImI0MTVlMWU3LTEwOGUtNGZmNy05NGMyLTYwN2Q1OThiZjE5MSIsImlhdCI6MTY0MzIyNDI3MCwic3ViIjoiZGV2ZWxvcGVyLzU4YTViNTllLTM3MGUtZmM0NC1mOGEyLWIwNjgyN2Q3NzhkYSIsInNjb3BlcyI6WyJyb3lhbGUiXSwibGltaXRzIjpbeyJ0aWVyIjoiZGV2ZWxvcGVyL3NpbHZlciIsInR5cGUiOiJ0aHJvdHRsaW5nIn0seyJjaWRycyI6WyIxODcuMTQwLjcwLjEyMSJdLCJ0eXBlIjoiY2xpZW50In1dfQ.YDHst6jQyUApBD3tW2Y_11-TkR4FOKEv-N7RjVULJGdC8CZn_tfazsmf1MKFqWDemP1YIWXEFUkn2bUYpcrv6g'
def getData(self, url):
head = {f'authorization': f'Bearer {self.my_token}'}
resp = requests.get(url=url, headers=head)
data = json.loads(resp.text)
return data
def getPlayerName(self):
"""Obtiene el nombre del jugador mediante el tag"""
url = 'https://api.clashroyale.com/v1/players/' + '%23' + self.tag
data = self.getData(url)
return data['name']
def getFavoriteCard(self):
"""Obtiene la carta favorita del jugador mediante el tag"""
url = 'https://api.clashroyale.com/v1/players/' + '%23' + self.tag
data = self.getData(url)
return data['currentFavouriteCard']['name']
def getWinsLosses(self):
"""Obtiene la cantidad de wins/losses del jugador mediante el tag"""
url = 'https://api.clashroyale.com/v1/players/' + '%23' + self.tag
data = self.getData(url)
return f"Tienes {data['wins']} victorias y {data['losses']} derrotas al dia de hoy"
def getNextChest(self):
"""Obtiene el siguiente cofre"""
url = 'https://api.clashroyale.com/v1/players/' + '%23' + self.tag + '/upcomingchests'
data = self.getData(url)
for data['items'] in data['items']:
# return f"En tu siguente cofre te saldra {(data['items']['name'])}"
print(f"Dentro de {(data['items']['index'])} cofres te saldra {(data['items']['name'])}")
return " "
def checkplayertag(self):
"""Valida la etiqueta para continuar con los procesos"""
url = 'https://api.clashroyale.com/v1/players/' + '%23' + self.tag
head = {f'authorization': f'Bearer {self.my_token}'}
resp = requests.get(url=url, headers=head)
if resp.status_code == 200:
return True
else:
return False
if __name__ == "__main__":
ok = False
bye = 1
oktag = ''
while not ok:
tag = input(' Hola \n Teclea tu etiqueta de ClashRoyale\n')
tag = tag.upper().replace('O', '0')
tag = list(tag)
if tag[0] == '#':
tag = tag[1:]
oktag = oktag.join(tag)
crplayer = ClashRoyale(oktag)
if crplayer.checkplayertag() == True:
print(f'Tu etiqueta es {oktag}\n')
else:
print('Tu etiqueta tiene un error, presiona 0 para corregir')
os.system('exit')
ok = int(input('¿Es correcto? \n 1 = SI \n 0 = No, Corregir\n '))
clearConsole()
while bye != 0:
print('Hola ' + crplayer.getPlayerName() + ' bienvenido')
bye = int(input('¿Que deseas hacer?\n\n'
'1.- Saber tu siguente cofre \n'
'2.- Saber tu carta favorita \n'
'3.- Victorias y derrotas \n'
'0.- Salir\n'))
if bye == 1:
print(crplayer.getNextChest())
elif bye == 2:
print(crplayer.getFavoriteCard())
elif bye == 3:
print(crplayer.getWinsLosses())
else:
bye = 0