coollsd commited on
Commit
6f8e3b5
·
verified ·
1 Parent(s): a94eb1f

Update leaderboard.py

Browse files
Files changed (1) hide show
  1. leaderboard.py +115 -114
leaderboard.py CHANGED
@@ -1,114 +1,115 @@
1
- import requests
2
- import time
3
- import json
4
- from discord_webhook import DiscordWebhook, DiscordEmbed
5
-
6
- proclubs_memberscareer_api = "https://proclubs.ea.com/api/fc/members/career/stats?platform=common-gen5&clubId=481259"
7
- keepthescore_api = "https://keepthescore.com/api/yrnfhgqvjhcyp/board/"
8
- headers = {
9
- "User-Agent": "Mozilla/5.0",
10
- "Accept": "application/json"
11
- }
12
- discord_webhook_link2 = "https://discord.com/api/webhooks/1304573170086449154/O2QiVs0o20alfSjLMfbfiF8qdd9-yJW2_BXLcDH1rfwxZVScJ866Ir_BdcmhMIcuhMVk"
13
-
14
- with open("stinkies.json", "r") as f:
15
- custom_names = json.load(f)
16
-
17
- previous_stats = {}
18
-
19
- def fetch_player_stats():
20
- response = requests.get(proclubs_memberscareer_api, headers=headers, timeout=10)
21
- response.raise_for_status()
22
- data = response.json()
23
- return data.get("members", [])
24
-
25
- def fetch_hat_tricks():
26
- response = requests.get(keepthescore_api, timeout=10)
27
- response.raise_for_status()
28
- data = response.json()
29
-
30
- hat_tricks = {player["name"]: player["score"] for player in data["players"]}
31
- return hat_tricks
32
-
33
- def send_leaderboard(leaderboard):
34
- embed = DiscordEmbed(
35
- title=f"Leaderboard <t:{int(time.time())}:f>",
36
- color=None
37
- )
38
-
39
- for rank, player in enumerate(leaderboard, start=1):
40
- embed.add_embed_field(
41
- name=f"{rank}. {player['custom_name']}",
42
- 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']}",
43
- inline=True
44
- )
45
-
46
- webhook = DiscordWebhook(url=discord_webhook_link2)
47
- webhook.add_embed(embed)
48
- webhook.execute()
49
- print("posted leaderboard")
50
-
51
- def get_leaderboard():
52
- player_stats = fetch_player_stats()
53
- hat_tricks = fetch_hat_tricks()
54
- leaderboard = []
55
-
56
- for player in player_stats:
57
- name = player.get("name")
58
- goals = int(player.get("goals", 0))
59
- assists = int(player.get("assists", 0))
60
- total_goals_assists = goals + assists
61
- hat_tricks_count = hat_tricks.get(name, 0)
62
- matches = int(player.get("gamesPlayed", 0))
63
- man_of_the_match = int(player.get("manOfTheMatch", 0))
64
-
65
- custom_name = custom_names.get(name, name)
66
-
67
- leaderboard.append({
68
- "name": name,
69
- "custom_name": custom_name,
70
- "goals": goals,
71
- "assists": assists,
72
- "total": total_goals_assists,
73
- "hat_tricks": hat_tricks_count,
74
- "matches": matches,
75
- "man_of_the_match": man_of_the_match
76
- })
77
-
78
- leaderboard = sorted(leaderboard, key=lambda x: x["total"], reverse=True)
79
- return leaderboard
80
-
81
- def has_changes(current_stats):
82
- global previous_stats
83
- for player in current_stats:
84
- name = player["name"]
85
- goals = player["goals"]
86
- assists = player["assists"]
87
-
88
- if name not in previous_stats or previous_stats[name]["goals"] != goals or previous_stats[name]["assists"] != assists:
89
- return True
90
-
91
- previous_stats = {player["name"]: {"goals": player["goals"], "assists": player["assists"]} for player in current_stats}
92
- return False
93
-
94
- def imsurejbbolterwillenjoydissectingthisframebyframe():
95
- global previous_stats
96
- while True:
97
- try:
98
- current_stats = get_leaderboard()
99
-
100
- if has_changes(current_stats):
101
- send_leaderboard(current_stats)
102
- previous_stats = {player["name"]: {"goals": player["goals"], "assists": player["assists"]} for player in current_stats}
103
-
104
- except requests.exceptions.RequestException as e:
105
- print(f"oh noes an error {e} retrying in 10 seconds")
106
- time.sleep(10)
107
-
108
- except Exception as e:
109
- print(f"my god not another error {e} oh well retrying in 10 seconds")
110
- time.sleep(10)
111
-
112
- time.sleep(60)
113
-
114
- imsurejbbolterwillenjoydissectingthisframebyframe()
 
 
1
+ import requests
2
+ import time
3
+ import json
4
+ from discord_webhook import DiscordWebhook, DiscordEmbed
5
+
6
+ proclubs_memberscareer_api = "https://proclubs.ea.com/api/fc/members/career/stats?platform=common-gen5&clubId=481259"
7
+ keepthescore_api = "https://keepthescore.com/api/yrnfhgqvjhcyp/board/"
8
+ headers = {
9
+ "User-Agent": "Mozilla/5.0",
10
+ "Accept": "application/json"
11
+ }
12
+ discord_webhook_link2 = "https://discord.com/api/webhooks/1304573170086449154/O2QiVs0o20alfSjLMfbfiF8qdd9-yJW2_BXLcDH1rfwxZVScJ866Ir_BdcmhMIcuhMVk"
13
+
14
+ with open("stinkies.json", "r") as f:
15
+ custom_names = json.load(f)
16
+
17
+ previous_stats = {}
18
+
19
+ def fetch_player_stats():
20
+ response = requests.get(proclubs_memberscareer_api, headers=headers, timeout=10)
21
+ response.raise_for_status()
22
+ data = response.json()
23
+ return data.get("members", [])
24
+
25
+ def fetch_hat_tricks():
26
+ response = requests.get(keepthescore_api, timeout=10)
27
+ response.raise_for_status()
28
+ data = response.json()
29
+
30
+ hat_tricks = {player["name"]: player["score"] for player in data["players"]}
31
+ return hat_tricks
32
+
33
+ def send_leaderboard(leaderboard):
34
+ embed = DiscordEmbed(
35
+ title=f"Leaderboard <t:{int(time.time())}:f>",
36
+ color=None
37
+ )
38
+
39
+ for rank, player in enumerate(leaderboard, start=1):
40
+ embed.add_embed_field(
41
+ name=f"{rank}. {player['custom_name']}",
42
+ 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']}",
43
+ inline=True
44
+ )
45
+
46
+ webhook = DiscordWebhook(url=discord_webhook_link2)
47
+ webhook.add_embed(embed)
48
+ webhook.execute()
49
+ print("posted leaderboard")
50
+
51
+ def get_leaderboard():
52
+ player_stats = fetch_player_stats()
53
+ hat_tricks = fetch_hat_tricks()
54
+ leaderboard = []
55
+
56
+ for player in player_stats:
57
+ name = player.get("name")
58
+ goals = int(player.get("goals", 0))
59
+ assists = int(player.get("assists", 0))
60
+ total_goals_assists = goals + assists
61
+ hat_tricks_count = hat_tricks.get(name, 0)
62
+ matches = int(player.get("gamesPlayed", 0))
63
+ man_of_the_match = int(player.get("manOfTheMatch", 0))
64
+
65
+ custom_name = custom_names.get(name, name)
66
+
67
+ leaderboard.append({
68
+ "name": name,
69
+ "custom_name": custom_name,
70
+ "goals": goals,
71
+ "assists": assists,
72
+ "total": total_goals_assists,
73
+ "hat_tricks": hat_tricks_count,
74
+ "matches": matches,
75
+ "man_of_the_match": man_of_the_match
76
+ })
77
+
78
+ leaderboard = sorted(leaderboard, key=lambda x: x["total"], reverse=True)
79
+ return leaderboard
80
+
81
+ def has_changes(current_stats):
82
+ global previous_stats
83
+ for player in current_stats:
84
+ name = player["name"]
85
+ goals = player["goals"]
86
+ assists = player["assists"]
87
+
88
+ if name not in previous_stats or previous_stats[name]["goals"] != goals or previous_stats[name]["assists"] != assists:
89
+ return True
90
+
91
+ previous_stats = {player["name"]: {"goals": player["goals"], "assists": player["assists"]} for player in current_stats}
92
+ return False
93
+
94
+ def imsurejbbolterwillenjoydissectingthisframebyframe():
95
+ global previous_stats
96
+ while True:
97
+ try:
98
+ current_stats = get_leaderboard()
99
+
100
+ if has_changes(current_stats):
101
+ send_leaderboard(current_stats)
102
+ previous_stats = {player["name"]: {"goals": player["goals"], "assists": player["assists"]} for player in current_stats}
103
+
104
+ except requests.exceptions.RequestException as e:
105
+ print(f"oh noes an error {e} retrying in 10 seconds")
106
+ time.sleep(10)
107
+
108
+ except Exception as e:
109
+ print(f"my god not another error {e} oh well retrying in 10 seconds")
110
+ time.sleep(10)
111
+
112
+ time.sleep(60)
113
+
114
+ if __name__ == "__main__":
115
+ imsurejbbolterwillenjoydissectingthisframebyframe()