diff --git a/cogs/football.py b/cogs/football.py index 4ad793e..1f77c85 100644 --- a/cogs/football.py +++ b/cogs/football.py @@ -2,7 +2,7 @@ from decorators import help from discord.ext import commands from enums.help_categories import Category from functions import checks, config -from functions.football import getMatches, getTable +from functions.football import getMatches, getTable, get_jpl_code class Football(commands.Cog): @@ -36,6 +36,13 @@ class Football(commands.Cog): async def table(self, ctx, *args): await ctx.send(getTable()) + @commands.check(checks.isMe) + @jpl.command(name="Update") + async def update(self, ctx): + code = get_jpl_code() + config.config("jpl", code) + await ctx.message.add_reaction("✅") + def setup(client): client.add_cog(Football(client)) diff --git a/files/help.json b/files/help.json index 058ba7e..d6112ac 100644 --- a/files/help.json +++ b/files/help.json @@ -56,6 +56,7 @@ "jpl": "Informatie over de Jupiler Pro League.", "jpl matches": "Bekijk de wedstrijden die gespeeld worden op [Week]. Default naar de huidige speeldag.", "jpl table": "De huidige stand van het klassement.", + "jpl update": "Haalt de nieuwe code voor de competitie van dit jaar op.", "leaderboard": "Bekijk de Top 10 van [Categorie].\nIndien je geen categorie opgeeft krijg je een lijst van categorieën.", "les": "Bekijk het lessenrooster voor [Dag] in het [Jaargang]-de jaar.\nIndien je geen dag opgeeft, is dit standaard vandaag. De jaargang is standaard 2.\nLes Morgen/Overmorgen werkt ook.", "lmgtfy": "Stuur iemand een LMGTFY link wanneer ze je een domme vraag stellen in plaats van het zelf op te zoeken.\nQueries met spaties moeten **niet** tussen aanhalingstekens staan.", diff --git a/functions/football.py b/functions/football.py index 092a90c..0648096 100644 --- a/functions/football.py +++ b/functions/football.py @@ -1,15 +1,20 @@ -from enum import Enum +from typing import Optional + from attr import dataclass, field +from datetime import datetime +from enum import Enum from functions.timeFormatters import fromString from functions.scrapers.sporza import getJPLMatches, getJPLTable from functions.stringFormatters import leadingZero -from datetime import datetime +import re +from requests import get import tabulate class Status(Enum): AfterToday = "--:--" NotStarted = "--:--" + Postponed = "--:--" Over = "Einde" HalfTime = "Rust" @@ -24,7 +29,7 @@ class Match: homeScore: int = 0 away: str = field(init=False) awayScore: int = 0 - start: datetime = field(init=False) + start: Optional[datetime] = field(init=False) date: str = field(init=False) weekDay: str = field(init=False) status: Status = field(init=False) @@ -42,9 +47,13 @@ class Match: self.homeScore = self.matchDict[Navigation.HomeScore.value] self.awayScore = self.matchDict[Navigation.AwayScore.value] - self.start = fromString(self.matchDict["startDateTime"], formatString="%Y-%m-%dT%H:%M:%S.%f%z") - self.date = self.start.strftime("%d/%m") - self.weekDay = self._getWeekday() + if "startDateTime" in self.matchDict: + self.start = fromString(self.matchDict["startDateTime"], formatString="%Y-%m-%dT%H:%M:%S.%f%z") + else: + self.start = None + + self.date = self.start.strftime("%d/%m") if self.start is not None else "Uitgesteld" + self.weekDay = self._getWeekday() if self.start is not None else "??" def _getStatus(self, status: str): """ @@ -65,6 +74,7 @@ class Match: statusses: dict = { "after_today": Status.AfterToday.value, "not_started": Status.NotStarted.value, + "postponed": Status.Postponed.value, "end": Status.Over.value } @@ -88,6 +98,9 @@ class Match: """ Returns a string representing the scoreboard """ + if self.start is None: + return "??" + # No score to show yet, show time when the match starts if not self._hasStarted(): return "{}:{}".format(leadingZero(str(self.start.hour)), leadingZero(str(self.start.minute))) @@ -95,7 +108,7 @@ class Match: return "{} - {}".format(self.homeScore, self.awayScore) def _hasStarted(self): - return self.status not in [Status.AfterToday.value, Status.NotStarted.value] + return self.status not in [Status.AfterToday.value, Status.NotStarted.value, Status.Postponed.value] class Navigation(Enum): @@ -162,3 +175,14 @@ def _formatRow(row): scoresArray.insert(1, row.find_all("a")[0].renderContents().decode("utf-8").split("