Skip to content

Commit c808aab

Browse files
Merge remote-tracking branch 'upstream/main' into JesusAEE
2 parents dfe0d34 + ff76062 commit c808aab

File tree

2 files changed

+775
-679
lines changed

2 files changed

+775
-679
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""
2+
* EJERCICIO:
3+
* ¡Rubius tiene su propia skin en Fortnite!
4+
* Y va a organizar una competición para celebrarlo.
5+
* Esta es la lista de participantes:
6+
* https://x.com/Rubiu5/status/1840161450154692876
7+
*
8+
* Desarrolla un programa que obtenga el número de seguidores en
9+
* Twitch de cada participante, la fecha de creación de la cuenta
10+
* y ordene los resultados en dos listados.
11+
* - Usa el API de Twitch: https://dev.twitch.tv/docs/api/reference
12+
* (NO subas las credenciales de autenticación)
13+
* - Crea un ranking por número de seguidores y por antigüedad.
14+
* - Si algún participante no tiene usuario en Twitch, debe reflejarlo.
15+
"""
16+
17+
import requests
18+
19+
# Configura tus credenciales de Twitch
20+
CLIENT_ID = 'CLIENT_ID'
21+
CLIENT_SECRET = 'CLIENT_SECRET'
22+
23+
# Obtén el token de acceso
24+
def get_access_token(client_id, client_secret):
25+
url = 'https://id.twitch.tv/oauth2/token'
26+
params = {
27+
'client_id': client_id,
28+
'client_secret': client_secret,
29+
'grant_type': 'client_credentials'
30+
}
31+
response = requests.post(url, params=params)
32+
return response.json()['access_token']
33+
34+
# Obtén la información del usuario de Twitch
35+
def get_user_info(username, access_token):
36+
url = f'https://api.twitch.tv/helix/users?login={username}'
37+
headers = {
38+
'Client-ID': CLIENT_ID,
39+
'Authorization': f'Bearer {access_token}'
40+
}
41+
response = requests.get(url, headers=headers)
42+
data = response.json()
43+
if 'data' in data and data['data']:
44+
return data['data'][0]
45+
else:
46+
return None
47+
48+
# Lista de participantes
49+
participants = [
50+
"abby", "djmariio", "kiko rivera", "nissaxter", "shadoune", "ache", "doble", "knekro",
51+
"ollie", "silithur", "adri contreras", "elvisa", "koko", "orslok", "spokspongha", "agustin",
52+
"elyas360", "kronnozomber", "outconsumer", "spreen", "alexby", "folagor", "leviathan",
53+
"papi gavi", "spursito", "ampeter", "grefg", "lit killah", "paracetamor", "staxx", "ander",
54+
"guanyar", "lola lolita", "patica", "suzyroxx", "ari gameplays", "hika", "lolito", "paula gonu",
55+
"vicens", "arigeli", "hiper", "luh", "pausenpaii", "vituber", "auronplay", "ibai", "luzu",
56+
"perxitaa", "werlyb", "axozer", "ibelky", "mangel", "plex", "xavi", "beniju", "illojuan",
57+
"mayichi", "polispol", "xcry", "by calitos", "imantado", "melo", "quackity", "xokas", "byviruzz",
58+
"irina isasia", "missasinfonia", "recuerdop", "zarcort", "carrera", "jesskiu", "mixwell",
59+
"reven", "zeling", "celopan", "jopa", "mr.jagger", "rivers", "zorman", "cheeto", "jordiwild",
60+
"nate gentile", "robertpg", "crystalmolly", "kenai souza", "nexxuz", "roier", "dario emehache",
61+
"keroro", "nia", "rojuu", "dheylo", "kidd keo", "nil ojeda", "rubius"
62+
]
63+
64+
access_token = get_access_token(CLIENT_ID, CLIENT_SECRET)
65+
66+
followers_ranking = []
67+
creation_date_ranking = []
68+
69+
for participant in participants:
70+
user_info = get_user_info(participant, access_token)
71+
if user_info:
72+
print(user_info) # Imprime la información del usuario para verificar las claves disponibles
73+
followers_ranking.append((participant, user_info.get('view_count', 'N/A')))
74+
creation_date_ranking.append((participant, user_info['created_at']))
75+
else:
76+
print(f"{participant} no tiene usuario en Twitch.")
77+
78+
# Ordenar por número de seguidores (view_count en este caso)
79+
followers_ranking.sort(key=lambda x: x[1], reverse=True)
80+
81+
# Ordenar por fecha de creación
82+
creation_date_ranking.sort(key=lambda x: x[1])
83+
84+
print("Ranking por número de seguidores:")
85+
for user in followers_ranking:
86+
print(user)
87+
88+
print("\nRanking por antigüedad:")
89+
for user in creation_date_ranking:
90+
print(user)

0 commit comments

Comments
 (0)