-
Notifications
You must be signed in to change notification settings - Fork 4k
/
mouredev.py
101 lines (81 loc) · 3.56 KB
/
mouredev.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
import requests
def get_access_token(client_id: str, client_secret: str) -> str:
url = "https://id.twitch.tv/oauth2/token"
params = {
"client_id": client_id,
"client_secret": client_secret,
"grant_type": "client_credentials"
}
response = requests.post(url, params=params)
response.raise_for_status()
return response.json().get("access_token")
def get_user_info(token: str, client_id: str, login: str):
url = "https://api.twitch.tv/helix/users"
headers = {
"Authorization": f"Bearer {token}",
"Client-Id": client_id
}
params = {"login": login}
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
data = response.json().get("data", None)
if not data:
return None
return data[0]
def get_total_followers(token: str, client_id: str, id: str) -> int:
url = "https://api.twitch.tv/helix/channels/followers"
headers = {
"Authorization": f"Bearer {token}",
"Client-Id": client_id
}
params = {"broadcaster_id": id}
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
return response.json().get("total", 0)
CLIENT_ID = "mi_client_id"
CLIENT_SECRET = "mi_client_secret"
users = [
"littleragergirl", "ache", "adricontreras4", "agustin51", "alexby11", "ampeterby7", "tvander",
"arigameplays", "arigeli_", "auronplay", "axozer", "beniju03", "bycalitos",
"byviruzz", "carreraaa", "celopan", "srcheeto", "crystalmolly", "darioemehache",
"dheylo", "djmariio", "doble", "elvisayomastercard", "elyas360", "folagorlives", "thegrefg",
"guanyar", "hika", "hiperop", "ibai", "ibelky_", "illojuan", "imantado",
"irinaissaia", "jesskiu", "jopa", "jordiwild", "kenaivsouza", "mrkeroro10",
"thekiddkeo95", "kikorivera", "knekro", "kokoop", "kronnozomberoficial", "leviathan",
"litkillah", "lolalolita", "lolitofdez", "luh", "luzu", "mangel", "mayichi",
"melo", "missasinfonia", "mixwell", "jaggerprincesa", "nategentile7", "nexxuz",
"lakshartnia", "nilojeda", "nissaxter", "olliegamerz", "orslok", "outconsumer", "papigavitv",
"paracetamor", "patica1999", "paulagonu", "pausenpaii", "perxitaa", "nosoyplex",
"polispol1", "quackity", "recuerd0p", "reventxz", "rivers_gg", "robertpg", "roier",
"ceuvebrokenheart", "rubius", "shadoune666", "silithur", "spok_sponha", "elspreen", "spursito",
"bystaxx", "suzyroxx", "vicens", "vitu", "werlyb", "xavi", "xcry", "elxokas",
"thezarcort", "zeling", "zormanworld", "mouredev"
]
users_data = []
not_found_users = []
token = get_access_token(CLIENT_ID, CLIENT_SECRET)
for username in users:
user = get_user_info(token, CLIENT_ID, username)
if user is None:
not_found_users.append(username)
else:
followers = get_total_followers(token, CLIENT_ID, user["id"])
users_data.append({
"username": username,
"created_at": user["created_at"],
"followers": followers
})
sort_by_followers = sorted(
users_data, key=lambda x: x["followers"], reverse=True)
sort_by_date = sorted(
users_data, key=lambda x: x["created_at"])
print("\nRanking por número de seguidores:")
for id, user, in enumerate(sort_by_followers):
print(f"{id + 1} - {user["username"]}: {user["followers"]} seguidores")
print("\nRanking por antigüedad:")
for id, user, in enumerate(sort_by_date):
print(f"{id + 1} - {user["username"]}: Creado el {user["created_at"]}")
if not_found_users:
print("\nUsuarios no encontrados:")
for user in not_found_users:
print(user)