diff --git a/app/cogs/trackdays.py b/app/cogs/trackdays.py index 45d08a0b..cfff67ce 100755 --- a/app/cogs/trackdays.py +++ b/app/cogs/trackdays.py @@ -2,6 +2,7 @@ from discord.ext import commands import discord import requests from bs4 import BeautifulSoup +import datetime class TrackDays(commands.Cog): @@ -68,8 +69,33 @@ class TrackDays(commands.Cog): months = soup.find_all("h4", class_="month") + # Create a month order mapping + month_order = { + "January": 1, + "February": 2, + "March": 3, + "April": 4, + "May": 5, + "June": 6, + "July": 7, + "August": 8, + "September": 9, + "October": 10, + "November": 11, + "December": 12, + } + + current_month = datetime.datetime.now().month + current_year = datetime.datetime.now().year + for month in months: month_name = month.text + month_num = month_order[month_name] + + # Skip if month is in the past + if month_num < current_month: + continue + data[month_name] = {"events": []} events = month.find_next( @@ -89,22 +115,6 @@ class TrackDays(commands.Cog): } ) - # Create a month order mapping - month_order = { - "January": 1, - "February": 2, - "March": 3, - "April": 4, - "May": 5, - "June": 6, - "July": 7, - "August": 8, - "September": 9, - "October": 10, - "November": 11, - "December": 12, - } - embed = discord.Embed(description="", color=discord.Color.blue(), type="rich") embed.set_author(name=track) @@ -113,14 +123,15 @@ class TrackDays(commands.Cog): ) for month in sorted(data.keys(), key=lambda x: month_order[x]): - embed.add_field( - name=f"🏁 {month} 🏁\n---------", - value="\n".join( - f"[{event['provider']}: {event['day']}]({event['reg_url']})" - for event in data[month]["events"] - ), - inline=False, - ) + if data[month]["events"]: # Only add field if there are events + embed.add_field( + name=f"🏁 {month} 🏁\n---------", + value="\n".join( + f"[{event['provider']}: {event['day']}]({event['reg_url']})" + for event in data[month]["events"] + ), + inline=False, + ) embed.set_footer(text="Pulled from https://www.trackpinata.com") await ctx.send_followup(embed=embed)