mirror of https://github.com/stijndcl/didier
Scrape current jpl matchweek every few hours
parent
d9d8c6a842
commit
2b96f3ec41
|
@ -3,7 +3,9 @@ from data.remind import Reminders
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
from enums.numbers import Numbers
|
from enums.numbers import Numbers
|
||||||
from functions import timeFormatters
|
from functions import timeFormatters
|
||||||
|
from functions.config import config
|
||||||
from functions.database import currency, poke, prison, birthdays, stats
|
from functions.database import currency, poke, prison, birthdays, stats
|
||||||
|
from functions.scraping import getMatchweek
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import requests
|
import requests
|
||||||
|
@ -21,6 +23,7 @@ class Tasks(commands.Cog):
|
||||||
self.checkBirthdays.start()
|
self.checkBirthdays.start()
|
||||||
self.updateMessageCounts.start()
|
self.updateMessageCounts.start()
|
||||||
self.sendReminders.start()
|
self.sendReminders.start()
|
||||||
|
self.updateMatchweek.start()
|
||||||
|
|
||||||
@tasks.loop(hours=1.0)
|
@tasks.loop(hours=1.0)
|
||||||
async def bankInterest(self):
|
async def bankInterest(self):
|
||||||
|
@ -218,9 +221,22 @@ class Tasks(commands.Cog):
|
||||||
async def beforeSendReminders(self):
|
async def beforeSendReminders(self):
|
||||||
await self.client.wait_until_ready()
|
await self.client.wait_until_ready()
|
||||||
|
|
||||||
# TODO
|
@tasks.loop(hours=2.0)
|
||||||
async def updateMatchweek(self):
|
async def updateMatchweek(self):
|
||||||
pass
|
"""
|
||||||
|
Task that checks the current JPL matchweek & changes the dict value
|
||||||
|
"""
|
||||||
|
matchweek = getMatchweek()
|
||||||
|
|
||||||
|
if matchweek is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Change the setting in the config
|
||||||
|
config("jpl_day", int(matchweek))
|
||||||
|
|
||||||
|
@updateMatchweek.before_loop
|
||||||
|
async def beforeUpdateMatchweek(self):
|
||||||
|
await self.client.wait_until_ready()
|
||||||
|
|
||||||
def getCurrentHour(self):
|
def getCurrentHour(self):
|
||||||
return timeFormatters.dateTimeNow().hour
|
return timeFormatters.dateTimeNow().hour
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"semester": "1", "year": "2", "years": 2, "jpl": 161733, "jpl_day": 4}
|
{"semester": "1", "year": "2", "years": 2, "jpl": 161733, "jpl_day": 21}
|
|
@ -1,3 +1,5 @@
|
||||||
|
import re
|
||||||
|
|
||||||
from requests import get
|
from requests import get
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
@ -49,4 +51,28 @@ def getMatchweek():
|
||||||
"""
|
"""
|
||||||
Parses the current JPL matchweek out of Sporza's site
|
Parses the current JPL matchweek out of Sporza's site
|
||||||
"""
|
"""
|
||||||
pass
|
resp = get("https://sporza.be/nl/categorie/voetbal/jupiler-pro-league/")
|
||||||
|
|
||||||
|
if resp.status_code != 200:
|
||||||
|
return None
|
||||||
|
|
||||||
|
bs = BeautifulSoup(resp.text, "html.parser")
|
||||||
|
matchdays = bs.find_all("section", attrs={"class": "sc-matchdays"})
|
||||||
|
|
||||||
|
if len(matchdays) < 2:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Table header
|
||||||
|
header = matchdays[1]
|
||||||
|
|
||||||
|
# Regex to find current matchday
|
||||||
|
r = re.compile(r"speeldag\s*\d+", flags=re.I)
|
||||||
|
|
||||||
|
match = r.search(str(header))
|
||||||
|
|
||||||
|
# Something went wrong, just ignore
|
||||||
|
if match is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# "Speeldag DD" -> split on space & take second
|
||||||
|
return match[0].split(" ")[1]
|
||||||
|
|
Loading…
Reference in New Issue