Closed michqo closed 1 year ago
If you find it useful then here is the code I have written to extract the edupageData
object which contains lunch data from html with beautifulsoup.
class Lunches(Module):
@ModuleHelper.logged_in
def get_lunch(self, date: datetime):
date_strftime = date.strftime("%Y%m%d")
request_url = (
f"https://{self.edupage.subdomain}.edupage.org/menu/?date={date_strftime}"
)
response = self.edupage.session.get(request_url).content.decode()
soup = BeautifulSoup(response, "html.parser")
script = soup.find("script", string=re.compile("edupageData"))
if (
isinstance(script, NavigableString)
or script is None
or script.string is None
):
raise TypeError("edupageData object not found")
lines = script.string.split("\n")
edupage_data_str = lines[20].strip()
edupage_data_str_object = edupage_data_str[13:-1]
lunch_data = orjson.loads(edupage_data_str_object)
lunches_data = lunch_data.get(self.edupage.subdomain)
try:
boarder_id = lunches_data.get("novyListok").get("addInfo").get("stravnikid")
# rest is unchanged
Thanks for letting us know!
I've fixed the issue in https://github.com/ivanhrabcak/edupage-api/commit/1359db50b76cfeb03d393fdfcaa7c489871fb1e8. EduPage just removed a space between edupageData
and :
😄
You can install the version of edupage-api
with the fix from the master
branch by using this command:
pip install git+https://github.com/ivanhrabcak/edupage-api.git
However, don't forget to uninstall the current version of edupage-api
first by using:
pip uninstall edupage-api
Wait, so there is no need to use beautiful soup to extract the edupageData
object? I thought the edupage /menu
endpoint changed, because when I tested making a request to /menu
it just returned html. I don't understand how the get_lunch
method works then.
Anyways thanks for fixing it, everything works now.
Describe the bug I'm getting an error in the
get_launch
method inLunches
class. More specifically in this line:The problem is that it seems like the response from the
https://subdomain.edupage.org/menu/?date=230418
url is not just an json object.Your code
Error message
Expected behavior
lunches
variable was supposed to be an instance of theLunch
class.Version