|
| 1 | +import requests |
| 2 | + |
| 3 | + |
| 4 | +def get_access_token(client_id: str, client_secret: str) -> str: |
| 5 | + url = "https://id.twitch.tv/oauth2/token" |
| 6 | + params = { |
| 7 | + "client_id": client_id, |
| 8 | + "client_secret": client_secret, |
| 9 | + "grant_type": "client_credentials" |
| 10 | + } |
| 11 | + response = requests.post(url, params=params) |
| 12 | + response.raise_for_status() |
| 13 | + return response.json().get("access_token") |
| 14 | + |
| 15 | + |
| 16 | +def get_user_info(token: str, client_id: str, login: str): |
| 17 | + url = "https://api.twitch.tv/helix/users" |
| 18 | + headers = { |
| 19 | + "Authorization": f"Bearer {token}", |
| 20 | + "Client-Id": client_id |
| 21 | + } |
| 22 | + params = {"login": login} |
| 23 | + response = requests.get(url, headers=headers, params=params) |
| 24 | + response.raise_for_status() |
| 25 | + data = response.json().get("data", None) |
| 26 | + |
| 27 | + if not data: |
| 28 | + return None |
| 29 | + |
| 30 | + return data[0] |
| 31 | + |
| 32 | + |
| 33 | +def get_total_followers(token: str, client_id: str, id: str) -> int: |
| 34 | + url = "https://api.twitch.tv/helix/channels/followers" |
| 35 | + headers = { |
| 36 | + "Authorization": f"Bearer {token}", |
| 37 | + "Client-Id": client_id |
| 38 | + } |
| 39 | + params = {"broadcaster_id": id} |
| 40 | + response = requests.get(url, headers=headers, params=params) |
| 41 | + response.raise_for_status() |
| 42 | + return response.json().get("total", 0) |
| 43 | + |
| 44 | + |
| 45 | +CLIENT_ID = "mi_client_id" |
| 46 | +CLIENT_SECRET = "mi_client_secret" |
| 47 | + |
| 48 | +users = [ |
| 49 | + "littleragergirl", "ache", "adricontreras4", "agustin51", "alexby11", "ampeterby7", "tvander", |
| 50 | + "arigameplays", "arigeli_", "auronplay", "axozer", "beniju03", "bycalitos", |
| 51 | + "byviruzz", "carreraaa", "celopan", "srcheeto", "crystalmolly", "darioemehache", |
| 52 | + "dheylo", "djmariio", "doble", "elvisayomastercard", "elyas360", "folagorlives", "thegrefg", |
| 53 | + "guanyar", "hika", "hiperop", "ibai", "ibelky_", "illojuan", "imantado", |
| 54 | + "irinaissaia", "jesskiu", "jopa", "jordiwild", "kenaivsouza", "mrkeroro10", |
| 55 | + "thekiddkeo95", "kikorivera", "knekro", "kokoop", "kronnozomberoficial", "leviathan", |
| 56 | + "litkillah", "lolalolita", "lolitofdez", "luh", "luzu", "mangel", "mayichi", |
| 57 | + "melo", "missasinfonia", "mixwell", "jaggerprincesa", "nategentile7", "nexxuz", |
| 58 | + "lakshartnia", "nilojeda", "nissaxter", "olliegamerz", "orslok", "outconsumer", "papigavitv", |
| 59 | + "paracetamor", "patica1999", "paulagonu", "pausenpaii", "perxitaa", "nosoyplex", |
| 60 | + "polispol1", "quackity", "recuerd0p", "reventxz", "rivers_gg", "robertpg", "roier", |
| 61 | + "ceuvebrokenheart", "rubius", "shadoune666", "silithur", "spok_sponha", "elspreen", "spursito", |
| 62 | + "bystaxx", "suzyroxx", "vicens", "vitu", "werlyb", "xavi", "xcry", "elxokas", |
| 63 | + "thezarcort", "zeling", "zormanworld", "mouredev" |
| 64 | +] |
| 65 | +users_data = [] |
| 66 | +not_found_users = [] |
| 67 | + |
| 68 | +token = get_access_token(CLIENT_ID, CLIENT_SECRET) |
| 69 | + |
| 70 | +for username in users: |
| 71 | + |
| 72 | + user = get_user_info(token, CLIENT_ID, username) |
| 73 | + |
| 74 | + if user is None: |
| 75 | + not_found_users.append(username) |
| 76 | + else: |
| 77 | + followers = get_total_followers(token, CLIENT_ID, user["id"]) |
| 78 | + users_data.append({ |
| 79 | + "username": username, |
| 80 | + "created_at": user["created_at"], |
| 81 | + "followers": followers |
| 82 | + }) |
| 83 | + |
| 84 | +sort_by_followers = sorted( |
| 85 | + users_data, key=lambda x: x["followers"], reverse=True) |
| 86 | + |
| 87 | +sort_by_date = sorted( |
| 88 | + users_data, key=lambda x: x["created_at"]) |
| 89 | + |
| 90 | +print("\nRanking por número de seguidores:") |
| 91 | +for id, user, in enumerate(sort_by_followers): |
| 92 | + print(f"{id + 1} - {user["username"]}: {user["followers"]} seguidores") |
| 93 | + |
| 94 | +print("\nRanking por antigüedad:") |
| 95 | +for id, user, in enumerate(sort_by_date): |
| 96 | + print(f"{id + 1} - {user["username"]}: Creado el {user["created_at"]}") |
| 97 | + |
| 98 | +if not_found_users: |
| 99 | + print("\nUsuarios no encontrados:") |
| 100 | + for user in not_found_users: |
| 101 | + print(user) |
0 commit comments