Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +35 -23
sportbet.py
CHANGED
@@ -18,13 +18,39 @@ async def fetch_nhl_scores():
|
|
18 |
|
19 |
async def fetch_nfl_scores():
|
20 |
current_year = datetime.now().year
|
21 |
-
current_week =
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
async with
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
class SportSelect(discord.ui.Select):
|
30 |
def __init__(self):
|
@@ -49,21 +75,7 @@ class SportSelect(discord.ui.Select):
|
|
49 |
view = GameSelect(upcoming_games, "NHL")
|
50 |
await interaction.followup.send("Select a game to bet on:", view=view, ephemeral=False)
|
51 |
elif selected_sport == "NFL":
|
52 |
-
|
53 |
-
if not scores:
|
54 |
-
await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
|
55 |
-
return
|
56 |
-
events = scores.get('sectionList', [])
|
57 |
-
upcoming_games = []
|
58 |
-
for section in events:
|
59 |
-
for game in section.get('events', []):
|
60 |
-
if game.get('eventStatus') == 2: # Check if the game is upcoming
|
61 |
-
upcoming_games.append(game)
|
62 |
-
if not upcoming_games:
|
63 |
-
await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
|
64 |
-
return
|
65 |
-
view = GameSelect(upcoming_games, "NFL")
|
66 |
-
await interaction.followup.send("Select a game to bet on:", view=view, ephemeral=False)
|
67 |
|
68 |
class GameSelect(discord.ui.View):
|
69 |
def __init__(self, games, league):
|
@@ -305,4 +317,4 @@ async def show_current_bets(interaction: discord.Interaction):
|
|
305 |
@app_commands.command(name="sportbet", description="Bet on sports games")
|
306 |
async def sportbet(interaction: discord.Interaction):
|
307 |
view = SportBetView()
|
308 |
-
await interaction.response.send_message("Select a sport to bet on:", view=view, ephemeral=False)
|
|
|
18 |
|
19 |
async def fetch_nfl_scores():
|
20 |
current_year = datetime.now().year
|
21 |
+
current_week = None
|
22 |
+
scores = None
|
23 |
+
|
24 |
+
for week in range(1, 18): # NFL regular season has 17 weeks
|
25 |
+
url = f"https://api.foxsports.com/bifrost/v1/nfl/scoreboard/segment/{current_year}-{week}-1?apikey={API_KEY}"
|
26 |
+
async with aiohttp.ClientSession() as session:
|
27 |
+
async with session.get(url) as response:
|
28 |
+
data = await response.json()
|
29 |
+
events = data['sectionList'][0]['events']
|
30 |
+
|
31 |
+
# Check if any game in this week is upcoming or in progress
|
32 |
+
if any(game['eventStatus'] in [1, 2] for game in events):
|
33 |
+
current_week = week
|
34 |
+
scores = data
|
35 |
+
break
|
36 |
+
|
37 |
+
return scores
|
38 |
+
|
39 |
+
async def show_nfl_games(interaction: discord.Interaction):
|
40 |
+
scores = await fetch_nfl_scores()
|
41 |
+
if not scores:
|
42 |
+
await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
|
43 |
+
return
|
44 |
+
|
45 |
+
events = scores.get('sectionList', [])[0].get('events', [])
|
46 |
+
upcoming_games = [game for game in events if game.get('eventStatus') in [1, 2]] # 1: Scheduled, 2: In Progress
|
47 |
+
|
48 |
+
if not upcoming_games:
|
49 |
+
await interaction.followup.send("No NFL games available for betting this week.", ephemeral=False)
|
50 |
+
return
|
51 |
+
|
52 |
+
view = GameSelect(upcoming_games, "NFL")
|
53 |
+
await interaction.followup.send("Select a game to bet on:", view=view, ephemeral=False)
|
54 |
|
55 |
class SportSelect(discord.ui.Select):
|
56 |
def __init__(self):
|
|
|
75 |
view = GameSelect(upcoming_games, "NHL")
|
76 |
await interaction.followup.send("Select a game to bet on:", view=view, ephemeral=False)
|
77 |
elif selected_sport == "NFL":
|
78 |
+
await show_nfl_games(interaction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
class GameSelect(discord.ui.View):
|
81 |
def __init__(self, games, league):
|
|
|
317 |
@app_commands.command(name="sportbet", description="Bet on sports games")
|
318 |
async def sportbet(interaction: discord.Interaction):
|
319 |
view = SportBetView()
|
320 |
+
await interaction.response.send_message("Select a sport to bet on:", view=view, ephemeral=False)
|