coollsd commited on
Commit
1cbf27e
β€’
1 Parent(s): ab98a08

Update tracker.py

Browse files
Files changed (1) hide show
  1. tracker.py +156 -156
tracker.py CHANGED
@@ -1,157 +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()
 
1
+ import requests
2
+ import time
3
+ import json
4
+ import random
5
+ from discord_webhook import DiscordWebhook, DiscordEmbed
6
+
7
+ api_url = "https://fcclub.deno.dev/"
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()