coollsd commited on
Commit
1e4819a
·
verified ·
1 Parent(s): 47a6106

Update sportbet.py

Browse files
Files changed (1) hide show
  1. sportbet.py +30 -13
sportbet.py CHANGED
@@ -18,13 +18,23 @@ async def fetch_nhl_scores():
18
 
19
  async def fetch_nfl_scores():
20
  current_year = datetime.now().year
21
- for week in range(1, 18): # NFL regular season has 17 weeks
22
- url = f"https://api.foxsports.com/bifrost/v1/nfl/scoreboard/segment/{current_year}-{week}-1?apikey={API_KEY}"
23
- async with aiohttp.ClientSession() as session:
24
- async with session.get(url) as response:
25
- data = await response.json()
26
- if data['sectionList'][0]['events'][0]['eventStatus'] == 2:
27
- return data
 
 
 
 
 
 
 
 
 
 
28
  return None # If no current week is found
29
 
30
  class SportSelect(discord.ui.Select):
@@ -54,7 +64,9 @@ class SportSelect(discord.ui.Select):
54
  if not scores:
55
  await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
56
  return
57
- events = scores.get('sectionList', [])[0].get('events', [])
 
 
58
  upcoming_games = [game for game in events if game.get('eventStatus') == 2]
59
  if not upcoming_games:
60
  await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
@@ -202,16 +214,21 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
202
  # Check for score updates
203
  for team, score in current_scores.items():
204
  if score > previous_scores.get(team, 0):
205
- team_name = self.game_data['lowerTeam']['longName'] if team == self.game_data['lowerTeam']['name'] else self.game_data['upperTeam']['longName']
206
- message = f"**{team_name}** SCORED! Current score: {current_scores[self.game_data['lowerTeam']['name']]} - {current_scores[self.game_data['upperTeam']['name']]}"
207
  await user.send(message)
208
 
209
  previous_scores = current_scores.copy()
210
 
211
  if is_final:
212
- away_score = current_scores.get(self.game_data['lowerTeam']['name'], 0)
213
- home_score = current_scores.get(self.game_data['upperTeam']['name'], 0)
214
- winner = self.game_data['lowerTeam']['name'] if away_score > home_score else self.game_data['upperTeam']['name']
 
 
 
 
 
215
 
216
  if winner == self.team:
217
  winnings = bet_amount * 2
 
18
 
19
  async def fetch_nfl_scores():
20
  current_year = datetime.now().year
21
+ # Start by fetching week 1 data to get quickNav
22
+ url = f"https://api.foxsports.com/bifrost/v1/nfl/scoreboard/segment/{current_year}-1-1?apikey={API_KEY}"
23
+ async with aiohttp.ClientSession() as session:
24
+ async with session.get(url) as response:
25
+ data = await response.json()
26
+ quick_nav = data.get('quickNav', [])
27
+ current_week_id = None
28
+ for week_info in quick_nav:
29
+ if week_info.get('selected'):
30
+ current_week_id = week_info['id'] # e.g., '2024-7-1'
31
+ break
32
+ if current_week_id:
33
+ # Fetch data for the current week
34
+ url_current_week = f"https://api.foxsports.com/bifrost/v1/nfl/scoreboard/segment/{current_week_id}?apikey={API_KEY}"
35
+ async with session.get(url_current_week) as response_current_week:
36
+ data_current_week = await response_current_week.json()
37
+ return data_current_week
38
  return None # If no current week is found
39
 
40
  class SportSelect(discord.ui.Select):
 
64
  if not scores:
65
  await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
66
  return
67
+ events = []
68
+ for section in scores.get('sectionList', []):
69
+ events.extend(section.get('events', []))
70
  upcoming_games = [game for game in events if game.get('eventStatus') == 2]
71
  if not upcoming_games:
72
  await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
 
214
  # Check for score updates
215
  for team, score in current_scores.items():
216
  if score > previous_scores.get(team, 0):
217
+ team_name = game['lowerTeam']['longName'] if team == game['lowerTeam']['name'] else game['upperTeam']['longName']
218
+ message = f"**{team_name}** SCORED! Current score: {current_scores[game['lowerTeam']['name']]} - {current_scores[game['upperTeam']['name']]}"
219
  await user.send(message)
220
 
221
  previous_scores = current_scores.copy()
222
 
223
  if is_final:
224
+ away_score = current_scores.get(game['lowerTeam']['name'], 0)
225
+ home_score = current_scores.get(game['upperTeam']['name'], 0)
226
+ if away_score > home_score:
227
+ winner = game['lowerTeam']['name']
228
+ elif home_score > away_score:
229
+ winner = game['upperTeam']['name']
230
+ else:
231
+ winner = None # It's a tie
232
 
233
  if winner == self.team:
234
  winnings = bet_amount * 2