mirror of https://github.com/stijndcl/didier
Compare commits
No commits in common. "968df71f988da1c555063465a3f0398143622cea" and "cbe1cf747fd595fa046662cb313b4117781a2214" have entirely different histories.
968df71f98
...
cbe1cf747f
|
|
@ -2,7 +2,7 @@ from decorators import help
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from enums.help_categories import Category
|
from enums.help_categories import Category
|
||||||
from functions import checks, config
|
from functions import checks, config
|
||||||
from functions.football import getMatches, getTable, get_jpl_code
|
from functions.football import getMatches, getTable
|
||||||
|
|
||||||
|
|
||||||
class Football(commands.Cog):
|
class Football(commands.Cog):
|
||||||
|
|
@ -36,13 +36,6 @@ class Football(commands.Cog):
|
||||||
async def table(self, ctx, *args):
|
async def table(self, ctx, *args):
|
||||||
await ctx.send(getTable())
|
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):
|
def setup(client):
|
||||||
client.add_cog(Football(client))
|
client.add_cog(Football(client))
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@
|
||||||
"jpl": "Informatie over de Jupiler Pro League.",
|
"jpl": "Informatie over de Jupiler Pro League.",
|
||||||
"jpl matches": "Bekijk de wedstrijden die gespeeld worden op [Week]. Default naar de huidige speeldag.",
|
"jpl matches": "Bekijk de wedstrijden die gespeeld worden op [Week]. Default naar de huidige speeldag.",
|
||||||
"jpl table": "De huidige stand van het klassement.",
|
"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.",
|
"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.",
|
"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.",
|
"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.",
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,15 @@
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from attr import dataclass, field
|
|
||||||
from datetime import datetime
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from attr import dataclass, field
|
||||||
from functions.timeFormatters import fromString
|
from functions.timeFormatters import fromString
|
||||||
from functions.scrapers.sporza import getJPLMatches, getJPLTable
|
from functions.scrapers.sporza import getJPLMatches, getJPLTable
|
||||||
from functions.stringFormatters import leadingZero
|
from functions.stringFormatters import leadingZero
|
||||||
import re
|
from datetime import datetime
|
||||||
from requests import get
|
|
||||||
import tabulate
|
import tabulate
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
AfterToday = "--:--"
|
AfterToday = "--:--"
|
||||||
NotStarted = "--:--"
|
NotStarted = "--:--"
|
||||||
Postponed = "--:--"
|
|
||||||
Over = "Einde"
|
Over = "Einde"
|
||||||
HalfTime = "Rust"
|
HalfTime = "Rust"
|
||||||
|
|
||||||
|
|
@ -29,7 +24,7 @@ class Match:
|
||||||
homeScore: int = 0
|
homeScore: int = 0
|
||||||
away: str = field(init=False)
|
away: str = field(init=False)
|
||||||
awayScore: int = 0
|
awayScore: int = 0
|
||||||
start: Optional[datetime] = field(init=False)
|
start: datetime = field(init=False)
|
||||||
date: str = field(init=False)
|
date: str = field(init=False)
|
||||||
weekDay: str = field(init=False)
|
weekDay: str = field(init=False)
|
||||||
status: Status = field(init=False)
|
status: Status = field(init=False)
|
||||||
|
|
@ -47,13 +42,9 @@ class Match:
|
||||||
self.homeScore = self.matchDict[Navigation.HomeScore.value]
|
self.homeScore = self.matchDict[Navigation.HomeScore.value]
|
||||||
self.awayScore = self.matchDict[Navigation.AwayScore.value]
|
self.awayScore = self.matchDict[Navigation.AwayScore.value]
|
||||||
|
|
||||||
if "startDateTime" in self.matchDict:
|
self.start = fromString(self.matchDict["startDateTime"], formatString="%Y-%m-%dT%H:%M:%S.%f%z")
|
||||||
self.start = fromString(self.matchDict["startDateTime"], formatString="%Y-%m-%dT%H:%M:%S.%f%z")
|
self.date = self.start.strftime("%d/%m")
|
||||||
else:
|
self.weekDay = self._getWeekday()
|
||||||
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):
|
def _getStatus(self, status: str):
|
||||||
"""
|
"""
|
||||||
|
|
@ -74,7 +65,6 @@ class Match:
|
||||||
statusses: dict = {
|
statusses: dict = {
|
||||||
"after_today": Status.AfterToday.value,
|
"after_today": Status.AfterToday.value,
|
||||||
"not_started": Status.NotStarted.value,
|
"not_started": Status.NotStarted.value,
|
||||||
"postponed": Status.Postponed.value,
|
|
||||||
"end": Status.Over.value
|
"end": Status.Over.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,9 +88,6 @@ class Match:
|
||||||
"""
|
"""
|
||||||
Returns a string representing the scoreboard
|
Returns a string representing the scoreboard
|
||||||
"""
|
"""
|
||||||
if self.start is None:
|
|
||||||
return "??"
|
|
||||||
|
|
||||||
# No score to show yet, show time when the match starts
|
# No score to show yet, show time when the match starts
|
||||||
if not self._hasStarted():
|
if not self._hasStarted():
|
||||||
return "{}:{}".format(leadingZero(str(self.start.hour)), leadingZero(str(self.start.minute)))
|
return "{}:{}".format(leadingZero(str(self.start.hour)), leadingZero(str(self.start.minute)))
|
||||||
|
|
@ -108,7 +95,7 @@ class Match:
|
||||||
return "{} - {}".format(self.homeScore, self.awayScore)
|
return "{} - {}".format(self.homeScore, self.awayScore)
|
||||||
|
|
||||||
def _hasStarted(self):
|
def _hasStarted(self):
|
||||||
return self.status not in [Status.AfterToday.value, Status.NotStarted.value, Status.Postponed.value]
|
return self.status not in [Status.AfterToday.value, Status.NotStarted.value]
|
||||||
|
|
||||||
|
|
||||||
class Navigation(Enum):
|
class Navigation(Enum):
|
||||||
|
|
@ -175,14 +162,3 @@ def _formatRow(row):
|
||||||
scoresArray.insert(1, row.find_all("a")[0].renderContents().decode("utf-8").split("<!--")[0])
|
scoresArray.insert(1, row.find_all("a")[0].renderContents().decode("utf-8").split("<!--")[0])
|
||||||
|
|
||||||
return scoresArray
|
return scoresArray
|
||||||
|
|
||||||
|
|
||||||
def get_jpl_code() -> int:
|
|
||||||
editions = get("https://api.sporza.be/web/soccer/competitions/48").json()["editions"]
|
|
||||||
newest_edition = editions[0]["_links"]["self"]["href"]
|
|
||||||
phase = get(newest_edition).json()["phases"][0]
|
|
||||||
phase_url = phase["_links"]["self"]["href"]
|
|
||||||
r = re.compile(r"\d+$")
|
|
||||||
match = re.search(r, phase_url)
|
|
||||||
|
|
||||||
return int(match[0])
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from functions import config
|
|
||||||
import re
|
import re
|
||||||
from requests import get
|
from requests import get
|
||||||
|
|
||||||
|
|
@ -39,8 +38,7 @@ def getJPLMatches(week: int):
|
||||||
"""
|
"""
|
||||||
JPL matches for a given matchweek
|
JPL matches for a given matchweek
|
||||||
"""
|
"""
|
||||||
jpl = config.get("jpl")
|
current_day = get("https://api.sporza.be/web/soccer/matchdays/161733/{}".format(week))
|
||||||
current_day = get(f"https://api.sporza.be/web/soccer/phases/{jpl}/matchdays/{week}")
|
|
||||||
|
|
||||||
# Something went wrong
|
# Something went wrong
|
||||||
if current_day.status_code != 200:
|
if current_day.status_code != 200:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue