coollsd commited on
Commit
83e0a7f
β€’
1 Parent(s): e917d3e

Upload 6 files

Browse files
leaderboard.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
manofthematch.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [
2
+ "https://tenor.com/view/ted-lasso-tedlassogifs-jason-sudeikis-youre-the-best-great-job-gif-20919742",
3
+ "https://tenor.com/view/lionel-messi-copa-del-mundo-lionel-messi-argentina-lionel-messi-campeon-mundial-lionel-messi-celebrando-lionel-messi-ganador-gif-27266878",
4
+ "https://tenor.com/view/man-of-the-match-cristiano-ronaldo-world-cup-fifa18-gif-12012520",
5
+ "https://tenor.com/view/cristiano-ronaldo-man-of-the-match-world-cup-fifa18-gif-12012525",
6
+ "https://tenor.com/view/neymar-neyney-neymar-jr-njr-psg-gif-17981619"
7
+ ]
motivationalquotes.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ "https://tenor.com/view/ted-lasso-afc-richmond-believe-gif-22969950",
3
+ "https://tenor.com/view/ted-lasso-tedlassogifs-be-curious-jason-sudeikis-dont-judge-gif-21044956",
4
+ "https://tenor.com/view/ted-lasso-tedlassogifs-jason-sudeikis-goldfish-be-a-goldfish-gif-20788379",
5
+ "https://tenor.com/view/it-will-all-work-out-ted-lasso-gif-27629930",
6
+ "https://tenor.com/view/ted-lasso-potential-1x01-gif-20622849",
7
+ "https://tenor.com/view/tedlassogifs-ted-lasso-jason-sudeikis-i-like-this-1x03-gif-20817136",
8
+ "https://tenor.com/view/ted-lasso-tedlassogifs-1x03-jason-sudeikis-high-praise-gif-20854600"
9
+ ]
playersdiscord.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "FrostedSnows": "<@689514474473914383>",
3
+ "daboss888": "<@867494557951459338>",
4
+ "Kimo_10x10": "<@824160724024557608>",
5
+ "jbb_jbz": "<@470880666264010754>",
6
+ "1M_ohW": "<@445205851037499392>",
7
+ "corysfatnyash": "<@1104426288703357039>",
8
+ "Aventic5618": "<@766816593170268210>",
9
+ "FredzPlayz": "<@792427838515052616>"
10
+ }
stinkies.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Kimo_10x10": "Kimo",
3
+ "daboss888": "Flare",
4
+ "FrostedSnows": "TornadoSnows",
5
+ "jbb_jbz": "jb :purple_circle:",
6
+ "corysfatnyash": "Cory",
7
+ "1M_ohW": "1M_oh",
8
+ "Aventic5618": "Aventic",
9
+ "FredzPlayz": "Fredz"
10
+ }
tracker.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import time
3
+ import json
4
+ import random
5
+ from discord_webhook import DiscordWebhook, DiscordEmbed
6
+
7
+ api_url = "https://proclubs.ea.com/api/fc/clubs/matches?platform=common-gen5&clubIds=481259&matchType=leagueMatch&maxResultCount=1"
8
+ keepthescore_api = "https://keepthescore.com/api/yrnfhgqvjhcyp/score/"
9
+ motm_webhook_url = "https://discord.com/api/webhooks/1305347802066325505/xmwdmbhBYHKa4hZbJVoURyFU1U5dyTR6eNyoJ-OboniKg0MMBsFZ2Zpp5jCFvfOHH18w"
10
+ tracker_webhook_url = "https://discord.com/api/webhooks/1302491524440789053/k2JcCmIYY1Vw5J7OrWfMYJDnvkk4Rsytf2Rs1NDYkntFc_od6G7pU7HyoOPyPztPxIUn"
11
+
12
+ headers = {
13
+ "User-Agent": "Mozilla/5.0",
14
+ "Accept": "application/json"
15
+ }
16
+
17
+ with open("stinkies.json", "r") as f:
18
+ custom_names = json.load(f)
19
+
20
+ with open("playersdiscord.json", "r") as f:
21
+ players_discord = json.load(f)
22
+
23
+ with open("motivationalquotes.json", "r") as f:
24
+ motivational_quotes = json.load(f)
25
+
26
+ with open("manofthematch.json", "r") as f:
27
+ motm_hall = json.load(f)
28
+
29
+ player_ids = {
30
+ "FrostedSnows": 49238511,
31
+ "daboss888": 49238506,
32
+ "Kimo_10x10": 49238510,
33
+ "jbb_jbz": 49290659,
34
+ "1M_ohW": 49238507,
35
+ "corysfatnyash": 49238508,
36
+ "Aventic5618": 49238509,
37
+ "FredzPlayz": 49290660
38
+ }
39
+
40
+ def fetch_match_data():
41
+ response = requests.get(api_url, headers=headers, timeout=10)
42
+ response.raise_for_status()
43
+ return response.json()[0]
44
+
45
+ def increment_score(player_id):
46
+ data = {
47
+ "player_id": player_id,
48
+ "score": 1,
49
+ "operation": "increment"
50
+ }
51
+ response = requests.post(keepthescore_api, json=data)
52
+ response.raise_for_status()
53
+ print(f"Incremented score for player ID {player_id}")
54
+
55
+ def send_discord_message(match_data):
56
+ clubs = match_data["clubs"]
57
+ rejection_fc = clubs["481259"]
58
+ opponent_id = next(club_id for club_id in clubs if club_id != "481259")
59
+ opponent_team = clubs[opponent_id]["details"]["name"]
60
+ rejection_score = rejection_fc["score"]
61
+ opponent_score = clubs[opponent_id]["score"]
62
+ match_score = f"{rejection_score} - {opponent_score}"
63
+
64
+ embed_color = 0
65
+ if rejection_fc["losses"] == "1":
66
+ embed_color = 16711680
67
+ elif rejection_fc["ties"] == "1":
68
+ embed_color = 2697513
69
+ elif rejection_fc["wins"] == "1":
70
+ embed_color = 65300
71
+
72
+ player_data_all_teams = match_data["players"]
73
+ man_of_match = next((p["playername"] for team in player_data_all_teams.values() for p in team.values() if p["mom"] == "1"), "none or probably an opponent in case this doesnt work")
74
+ match_timestamp = match_data["timestamp"]
75
+ formatted_timestamp = f"<t:{match_timestamp}:R>"
76
+
77
+ embed = DiscordEmbed(
78
+ title=match_score,
79
+ description=f"**Opponent:** {opponent_team}\n**Man of the Match:** {man_of_match}\n**Played:** {formatted_timestamp}\n\nPlayers:",
80
+ color=embed_color
81
+ )
82
+ embed.set_thumbnail(url=f"https://eafc24.content.easports.com/fifa/fltOnlineAssets/24B23FDE-7835-41C2-87A2-F453DFDB2E82/2024/fcweb/crests/256x256/l{clubs[opponent_id]['TEAM']}.png")
83
+
84
+ player_data_rejection_fc = player_data_all_teams["481259"]
85
+ sorted_players = sorted(player_data_rejection_fc.values(), key=lambda x: float(x["rating"]), reverse=True)
86
+
87
+ for player in sorted_players:
88
+ player_name = player["playername"]
89
+ custom_name = custom_names.get(player_name, player_name)
90
+ position = player["pos"]
91
+ rating = player["rating"]
92
+ goals = int(player["goals"])
93
+ assists = player["assists"]
94
+
95
+ if goals in [3, 4, 5]:
96
+ player_id = player_ids.get(player_name)
97
+ if player_id:
98
+ increment_score(player_id)
99
+
100
+ red_card_icon = "πŸŸ₯ " if player["redcards"] == "1" else ""
101
+ player_display_name = f"{red_card_icon}{custom_name} ({position})"
102
+
103
+ embed.add_embed_field(
104
+ name=player_display_name,
105
+ value=f"__Rating: {rating}__\n{goals} goals\n{assists} assists",
106
+ inline=True
107
+ )
108
+
109
+ if player["mom"] == "1":
110
+ send_motm_message(player_name)
111
+
112
+ webhook = DiscordWebhook(url=tracker_webhook_url)
113
+ webhook.add_embed(embed)
114
+ webhook.execute()
115
+ print(f"posted match {match_data['matchId']} with the score {match_score}")
116
+
117
+ if rejection_fc["losses"] == "1":
118
+ send_motivational_message()
119
+
120
+ def send_motivational_message():
121
+ message = random.choice(motivational_quotes)
122
+
123
+ webhook = DiscordWebhook(url=tracker_webhook_url, content=message)
124
+ webhook.execute()
125
+
126
+ def send_motm_message(player_name):
127
+ discord_tag = players_discord.get(player_name, "player")
128
+ msg_gif = random.choice(motm_hall)
129
+ main_message = f"{discord_tag} is the MAN OF THE MATCH! πŸ†"
130
+ motm_webhook = DiscordWebhook(url=motm_webhook_url, content=main_message)
131
+ motm_webhook.execute()
132
+ gif_message = DiscordWebhook(url=motm_webhook_url, content=msg_gif)
133
+ gif_message.execute()
134
+
135
+ def monitor_matches():
136
+ last_match_id = None
137
+
138
+ while True:
139
+ try:
140
+ match_data = fetch_match_data()
141
+ match_id = match_data["matchId"]
142
+
143
+ if match_id != last_match_id:
144
+ send_discord_message(match_data)
145
+ last_match_id = match_id
146
+
147
+ except requests.exceptions.RequestException as e:
148
+ print(f"oh noes an error {e} retrying in 10 seconds")
149
+ time.sleep(10)
150
+
151
+ except Exception as e:
152
+ print(f"my god not another error {e} oh well retrying in 10 seconds")
153
+ time.sleep(10)
154
+
155
+ time.sleep(60)
156
+
157
+ monitor_matches()