File size: 4,028 Bytes
6f8e3b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b55e729
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
112
113
114
import requests
import time
import json
from discord_webhook import DiscordWebhook, DiscordEmbed

proclubs_memberscareer_api = "https://proclubs.ea.com/api/fc/members/career/stats?platform=common-gen5&clubId=481259"
keepthescore_api = "https://keepthescore.com/api/yrnfhgqvjhcyp/board/"
headers = {
    "User-Agent": "Mozilla/5.0",
    "Accept": "application/json"
}
discord_webhook_link2 = "https://discord.com/api/webhooks/1304573170086449154/O2QiVs0o20alfSjLMfbfiF8qdd9-yJW2_BXLcDH1rfwxZVScJ866Ir_BdcmhMIcuhMVk"

with open("stinkies.json", "r") as f:
    custom_names = json.load(f)

previous_stats = {}

def fetch_player_stats():
    response = requests.get(proclubs_memberscareer_api, headers=headers, timeout=10)
    response.raise_for_status()
    data = response.json()
    return data.get("members", [])

def fetch_hat_tricks():
    response = requests.get(keepthescore_api, timeout=10)
    response.raise_for_status()
    data = response.json()
    
    hat_tricks = {player["name"]: player["score"] for player in data["players"]}
    return hat_tricks

def send_leaderboard(leaderboard):
    embed = DiscordEmbed(
        title=f"Leaderboard <t:{int(time.time())}:f>",
        color=None
    )
    
    for rank, player in enumerate(leaderboard, start=1):
        embed.add_embed_field(
            name=f"{rank}. {player['custom_name']}",
            value=f"__G/A: {player['total']}__\nGoals: {player['goals']}\nAssists: {player['assists']}\nHat-Tricks: {player['hat_tricks']}\nMatches: {player['matches']}\nMOTM: {player['man_of_the_match']}",
            inline=True
        )
    
    webhook = DiscordWebhook(url=discord_webhook_link2)
    webhook.add_embed(embed)
    webhook.execute()
    print("posted leaderboard")

def get_leaderboard():
    player_stats = fetch_player_stats()
    hat_tricks = fetch_hat_tricks()
    leaderboard = []
    
    for player in player_stats:
        name = player.get("name")
        goals = int(player.get("goals", 0))
        assists = int(player.get("assists", 0))
        total_goals_assists = goals + assists
        hat_tricks_count = hat_tricks.get(name, 0)
        matches = int(player.get("gamesPlayed", 0))
        man_of_the_match = int(player.get("manOfTheMatch", 0))
        
        custom_name = custom_names.get(name, name)
        
        leaderboard.append({
            "name": name,
            "custom_name": custom_name,
            "goals": goals,
            "assists": assists,
            "total": total_goals_assists,
            "hat_tricks": hat_tricks_count,
            "matches": matches,
            "man_of_the_match": man_of_the_match
        })
    
    leaderboard = sorted(leaderboard, key=lambda x: x["total"], reverse=True)
    return leaderboard

def has_changes(current_stats):
    global previous_stats
    for player in current_stats:
        name = player["name"]
        goals = player["goals"]
        assists = player["assists"]
        
        if name not in previous_stats or previous_stats[name]["goals"] != goals or previous_stats[name]["assists"] != assists:
            return True
    
    previous_stats = {player["name"]: {"goals": player["goals"], "assists": player["assists"]} for player in current_stats}
    return False

def imsurejbbolterwillenjoydissectingthisframebyframe():
    global previous_stats
    while True:
        try:
            current_stats = get_leaderboard()
            
            if has_changes(current_stats):
                send_leaderboard(current_stats)
                previous_stats = {player["name"]: {"goals": player["goals"], "assists": player["assists"]} for player in current_stats}
        
        except requests.exceptions.RequestException as e:
            print(f"oh noes an error {e} retrying in 10 seconds")
            time.sleep(10)
        
        except Exception as e:
            print(f"my god not another error {e} oh well retrying in 10 seconds")
            time.sleep(10)
        
        time.sleep(60)

imsurejbbolterwillenjoydissectingthisframebyframe()