Compare commits

..

No commits in common. "968df71f988da1c555063465a3f0398143622cea" and "cbe1cf747fd595fa046662cb313b4117781a2214" have entirely different histories.

4 changed files with 9 additions and 43 deletions

View File

@ -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, get_jpl_code
from functions.football import getMatches, getTable
class Football(commands.Cog):
@ -36,13 +36,6 @@ 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))

View File

@ -56,7 +56,6 @@
"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.",

View File

@ -1,20 +1,15 @@
from typing import Optional
from attr import dataclass, field
from datetime import datetime
from enum import Enum
from attr import dataclass, field
from functions.timeFormatters import fromString
from functions.scrapers.sporza import getJPLMatches, getJPLTable
from functions.stringFormatters import leadingZero
import re
from requests import get
from datetime import datetime
import tabulate
class Status(Enum):
AfterToday = "--:--"
NotStarted = "--:--"
Postponed = "--:--"
Over = "Einde"
HalfTime = "Rust"
@ -29,7 +24,7 @@ class Match:
homeScore: int = 0
away: str = field(init=False)
awayScore: int = 0
start: Optional[datetime] = field(init=False)
start: datetime = field(init=False)
date: str = field(init=False)
weekDay: str = field(init=False)
status: Status = field(init=False)
@ -47,13 +42,9 @@ class Match:
self.homeScore = self.matchDict[Navigation.HomeScore.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")
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 "??"
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()
def _getStatus(self, status: str):
"""
@ -74,7 +65,6 @@ class Match:
statusses: dict = {
"after_today": Status.AfterToday.value,
"not_started": Status.NotStarted.value,
"postponed": Status.Postponed.value,
"end": Status.Over.value
}
@ -98,9 +88,6 @@ 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)))
@ -108,7 +95,7 @@ class Match:
return "{} - {}".format(self.homeScore, self.awayScore)
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):
@ -175,14 +162,3 @@ def _formatRow(row):
scoresArray.insert(1, row.find_all("a")[0].renderContents().decode("utf-8").split("<!--")[0])
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])

View File

@ -1,5 +1,4 @@
from bs4 import BeautifulSoup
from functions import config
import re
from requests import get
@ -39,8 +38,7 @@ def getJPLMatches(week: int):
"""
JPL matches for a given matchweek
"""
jpl = config.get("jpl")
current_day = get(f"https://api.sporza.be/web/soccer/phases/{jpl}/matchdays/{week}")
current_day = get("https://api.sporza.be/web/soccer/matchdays/161733/{}".format(week))
# Something went wrong
if current_day.status_code != 200: