Skip to content

Commit

Permalink
Merge pull request #18 from ivansaul/refactor
Browse files Browse the repository at this point in the history
fix: add handling for quiz URLs
  • Loading branch information
ivansaul authored Nov 18, 2024
2 parents aa3a53b + 6347ebb commit 186fe6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/platzi/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/platzi/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 186fe6b

Please sign in to comment.