Skip to content

Commit 3e8687b

Browse files
authored
Merge pull request mouredev#6455 from SooHav/main
mouredev#40 - python
2 parents 59601a7 + b3c6959 commit 3e8687b

File tree

1 file changed

+241
-0
lines changed
  • Roadmap/40 - FORTNITE RUBIUS CUP/python

1 file changed

+241
-0
lines changed
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
# 40 FORTNITE RUBIUS CUP
2+
3+
import requests
4+
import base64
5+
from datetime import datetime
6+
import os
7+
from dotenv import load_dotenv
8+
9+
# Cargar las variables de entorno desde .env para obtener CLIENT_ID y CLIENT_SECRET
10+
load_dotenv()
11+
12+
CLIENT_ID = os.getenv("CLIENT_ID")
13+
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
14+
15+
# Funciones
16+
17+
18+
def obtener_token() -> str:
19+
url = "https://id.twitch.tv/oauth2/token"
20+
data = {
21+
"client_id": CLIENT_ID,
22+
"client_secret": CLIENT_SECRET,
23+
"grant_type": "client_credentials"
24+
}
25+
26+
headers = {
27+
"Content-Type": "application/x-www-form-urlencoded"
28+
}
29+
30+
response = requests.post(url, headers=headers, data=data)
31+
if response.status_code != 200:
32+
raise Exception(f"Error obteniendo el token de Twitch: {
33+
response.json()}.")
34+
35+
return response.json()["access_token"]
36+
37+
38+
def buscar_participante(token: str, login: str):
39+
url = f"https://api.twitch.tv/helix/users?login={login}"
40+
headers = {
41+
"Authorization": f"Bearer {token}",
42+
"Client-Id": CLIENT_ID
43+
}
44+
45+
response = requests.get(url, headers=headers)
46+
if response.status_code != 200:
47+
return {
48+
"login": login,
49+
"estado del usuario de twitch": "Inactivo"
50+
}
51+
resultados = response.json().get("data", [])
52+
if resultados:
53+
return {
54+
"id": resultados[0]["id"],
55+
"login": resultados[0]["login"],
56+
"usuario twitch": resultados[0]["display_name"],
57+
"creación de cuenta": (datetime.strptime(resultados[0]["created_at"], "%Y-%m-%dT%H:%M:%SZ")),
58+
"descripción": resultados[0]["description"],
59+
"estado del usuario de twitch": "activo"
60+
}
61+
return {}
62+
63+
64+
def buscar_seguidores_participante(token: str, id: str):
65+
url = f"https://api.twitch.tv/helix/channels/followers?broadcaster_id={id}"
66+
headers = {
67+
"Authorization": f"Bearer {token}",
68+
"Client-Id": CLIENT_ID
69+
}
70+
response = requests.get(url, headers=headers)
71+
if response.status_code != 200:
72+
return {
73+
"total de seguidores": 0,
74+
"estado del usuario de twitch": "Inactivo",
75+
"seguido desde": "Sin informacion disponible"
76+
}
77+
78+
resultados = response.json()
79+
total_seguidores = resultados.get("total", 0)
80+
81+
if resultados.get("data"):
82+
resultados_canal = resultados["data"][0]
83+
return {
84+
"total de seguidores": total_seguidores,
85+
"broadcaster id": resultados_canal['user_id'],
86+
"login del usuario": resultados_canal['user_login'],
87+
"seguido desde": resultados_canal['followed_at']
88+
}
89+
return {
90+
"total de seguidores": total_seguidores,
91+
"estado del usuario de twitch": "Activo",
92+
"seguido desde": "Sin informacion disponible"
93+
}
94+
95+
96+
def buscar_info_canal(token: str, broadcaster_id: str):
97+
url = f"https://api.twitch.tv/helix/channels?broadcaster_id={
98+
broadcaster_id}"
99+
headers = {
100+
"Authorization": f"Bearer {token}",
101+
"Client-Id": CLIENT_ID
102+
}
103+
response = requests.get(url, headers=headers)
104+
if response.status_code != 200:
105+
return {
106+
"juegos": "sin información",
107+
"tópicos del canal": "sin información",
108+
}
109+
resultados_canal = response.json().get("data", [])
110+
if resultados_canal:
111+
return {
112+
"juegos": resultados_canal[0]['game_name'],
113+
"tópicos del canal": resultados_canal[0]['content_classification_labels']
114+
}
115+
return {
116+
"juegos": "sin información",
117+
"tópicos del canal": "sin información",
118+
}
119+
120+
# Uso de codigo
121+
122+
123+
token = obtener_token()
124+
125+
participantes_lista = [
126+
'littleragergirl', 'DJMARIIO', 'KikoRivera', 'NISSAXTER',
127+
'SHADOUNE666', 'ACHE', 'DOBLE', 'KNEKRO',
128+
'OllieGamerz', 'SILITHUR', 'AdriContreras4', 'ElvisaYomastercard',
129+
'KOKO', 'ORSLOK', 'spok_sponha', 'agustin51',
130+
'elyas360', 'KronnoZomberOficial', 'Outconsumer', 'SPREEN',
131+
'ElSpreen', 'FolagorLives', 'Leviathan', 'PapiGaviTV',
132+
'Spursito', 'Ampeterby7', 'TheGrefg', 'LITkillah',
133+
'paracetamor', 'bysTaXx', 'tvandeR', 'GUANYAR',
134+
'LOLALOLITA', 'patica1999', 'SUZYROXX', 'ARIGAMEPLAYS',
135+
'HIKA', 'LOLITOFDEZ', 'PAULAGONU', 'VICENS',
136+
'ARIGELI_', 'Hiperop', 'LUH', 'PAUSENPAII',
137+
'VITU', 'AURONPLAY', 'IBAI', 'LUZU',
138+
'PERXITAA', 'WERLYB', 'AXOZER', 'IBELKY_',
139+
'MANGEL', 'NoSoyPlex', 'XAVI', 'BENIJU03',
140+
'ILLOJUAN', 'MAYICHI', 'POLISPOL1', 'XCRY',
141+
'BYCALITOS', 'IMANTADO', 'MELO', 'QUACKITY',
142+
'elxokas', 'BYVIRUZZ', 'IRINA ISASIA', 'MISSASINFONIA',
143+
'Recuerd0p', 'THEZARCORT', 'CARRERAAA', 'JESSKIU',
144+
'MIXWELL', 'REVENXZ', 'ZELING', 'CELOPAN',
145+
'JOPA', 'JaggerPrincesa', 'rivers_gg', 'ZormanWorld',
146+
'srcheeto', 'JORDIWILD', 'NATEGENTILE7', 'ROBERTPG',
147+
'CRYSTALMOLLY', 'kenaivsouza', 'NEXXUZ', 'ROIER',
148+
'DARIOEMEHACHE', 'MrKeroro10', 'LakshartNia', 'ROJUU',
149+
'DHEYLO', 'TheKiddKeo95', 'nilojeda', 'RUBIUS'
150+
]
151+
152+
153+
informacion_participantes_seguidores = []
154+
informacion_participantes_antiguedad = []
155+
156+
157+
for nombre in participantes_lista:
158+
try:
159+
participante = buscar_participante(token, nombre)
160+
info = {"usuario twitch": nombre}
161+
162+
if "id" in participante:
163+
info["id"] = participante["id"]
164+
info["estado del usuario de twitch"] = participante.get(
165+
"estado del usuario de twitch", "Inactivo")
166+
seguidores = buscar_seguidores_participante(
167+
token, participante["id"])
168+
info["total seguidores"] = int(
169+
seguidores.get("total de seguidores", 0))
170+
171+
if "broadcaster id" in seguidores:
172+
canal = buscar_info_canal(token, seguidores["broadcaster id"])
173+
info["juegos"] = canal.get(
174+
"juegos", "Informacion no disponible")
175+
info["tópicos del canal"] = canal.get()
176+
else:
177+
info["estado del usuario de twitch"] = "No tiene cuenta de twitch"
178+
info["total seguidores"] = 0
179+
180+
informacion_participantes_seguidores.append(info)
181+
182+
except Exception as e:
183+
print(f"Error al procesar {nombre}: {e}")
184+
185+
for nombre in participantes_lista:
186+
try:
187+
participante = buscar_participante(token, nombre)
188+
cuenta = {"usuario twitch": nombre}
189+
if "id" in participante:
190+
cuenta["id"] = participante["id"]
191+
cuenta["estado del usuario de twitch"] = participante.get(
192+
"estado del usuario de twitch", "Inactivo")
193+
cuenta["creación de cuenta"] = participante.get(
194+
"creación de cuenta", None)
195+
creacion = buscar_seguidores_participante(
196+
token, participante["id"])
197+
creacion["seguido desde"] = creacion. get("seguido desde", None)
198+
else:
199+
cuenta["estado del usuario de twitch"] = "No tiene cuenta de twitch"
200+
cuenta["creación de cuenta"] = None
201+
202+
informacion_participantes_antiguedad.append(cuenta)
203+
204+
except Exception as e:
205+
print(f"Error al procesar {nombre}: {e}")
206+
207+
208+
informacion_participantes_seguidores = sorted(
209+
informacion_participantes_seguidores,
210+
key=lambda x: x.get("total seguidores", 0),
211+
reverse=True
212+
)
213+
214+
215+
informacion_participantes_antiguedad = sorted(
216+
informacion_participantes_antiguedad,
217+
key=lambda x: x.get("creación de cuenta") if x.get(
218+
"creación de cuenta") is not None else datetime.min,
219+
reverse=True
220+
)
221+
# Participantes del evento Rubius Cup
222+
print("\nLista de los seguidores de los participantes del evento Rubius Cup en Twitch\n")
223+
for participante_evento_fortnite in informacion_participantes_seguidores:
224+
print(f"Participante: {participante_evento_fortnite['usuario twitch']}, Estado: {
225+
participante_evento_fortnite['estado del usuario de twitch']}, Seguidores: {participante_evento_fortnite['total seguidores']}")
226+
227+
print("\nLista de antiguedad de las cuentas de los participantes del evento Rubius Cup en Twitch\n")
228+
229+
# Participantes del evento Rubius Cup
230+
for participante_evento_fortnite in informacion_participantes_antiguedad:
231+
fecha_creacion = participante_evento_fortnite.get("creación de cuenta")
232+
233+
if isinstance(fecha_creacion, datetime):
234+
fecha = fecha_creacion.strftime("%d-%m-%Y %H:%M:%S")
235+
elif isinstance(fecha_creacion, str):
236+
fecha = fecha_creacion
237+
else:
238+
fecha = "Información no disponible"
239+
240+
print(f"Participante: {participante_evento_fortnite['usuario twitch']}, Estado: {
241+
participante_evento_fortnite['estado del usuario de twitch']}, Creación de cuenta: {fecha}")

0 commit comments

Comments
 (0)