From 6347ebb586269ebaaa2901cafd4d4212f77d5ff8 Mon Sep 17 00:00:00 2001 From: ivansaul Date: Sun, 17 Nov 2024 20:04:44 -0500 Subject: [PATCH] fix: add handling for quiz URLs --- src/platzi/async_api.py | 6 ++++++ src/platzi/collectors.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/platzi/async_api.py b/src/platzi/async_api.py index ff70e62..3524c8a 100644 --- a/src/platzi/async_api.py +++ b/src/platzi/async_api.py @@ -180,6 +180,12 @@ async def download(self, url: str, **kwargs): Logger.print(f"[{dst.name}]", "[DOWNLOADING]") await self.save_page(unit.url, path=dst) + # download quiz + if unit.type == TypeUnit.QUIZ: + dst = CHAP_DIR / f"{file_name}.mhtml" + Logger.print(f"[{dst.name}]", "[DOWNLOADING]") + await self.save_page(unit.url, path=dst) + print("=" * 100) @try_except_request diff --git a/src/platzi/collectors.py b/src/platzi/collectors.py index decab74..21b902a 100644 --- a/src/platzi/collectors.py +++ b/src/platzi/collectors.py @@ -73,6 +73,14 @@ async def get_unit(context: BrowserContext, url: str) -> Unit: TITLE_SELECTOR = ".MaterialDesktopHeading_MaterialDesktopHeading-info__title__DaYr2" EXCEPTION = Exception("Could not collect unit data") + if "/quiz/" in url: + return Unit( + url=url, + title="Quiz", + type=TypeUnit.QUIZ, + slug=slugify("Quiz"), + ) + try: page = await context.new_page() await page.goto(url)