Compare commits
No commits in common. "f12ab4e3a022efdac1a4950c75a285c90625d8dd" and "aa33c361c25db1b37c70a13c94a2f5c58f42a708" have entirely different histories.
f12ab4e3a0
...
aa33c361c2
2 changed files with 16 additions and 11 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
venv/
|
|
||||||
__pycache__/
|
|
||||||
*.pyc
|
|
||||||
24
scrape.py
24
scrape.py
|
|
@ -36,7 +36,8 @@ CONTENT_SELECTORS = [
|
||||||
|
|
||||||
|
|
||||||
def sanitize(name: str) -> str:
|
def sanitize(name: str) -> str:
|
||||||
name = re.sub(r'[<>:"/\\|?*\r\n\t]', '', str(name)).strip().strip(".")
|
name = re.sub(r'[<>:"/\|?*
|
||||||
|
]', '', str(name)).strip().strip(".")
|
||||||
return name[:120]
|
return name[:120]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -61,7 +62,9 @@ def html_to_md(raw: str) -> str:
|
||||||
def write_lesson(output_dir: Path, course_title: str, lesson_title: str, body: str) -> str:
|
def write_lesson(output_dir: Path, course_title: str, lesson_title: str, body: str) -> str:
|
||||||
stem = f"{sanitize(course_title)} -- {sanitize(lesson_title)}"
|
stem = f"{sanitize(course_title)} -- {sanitize(lesson_title)}"
|
||||||
out = output_dir / f"{stem}.md"
|
out = output_dir / f"{stem}.md"
|
||||||
out.write_text(f"# {lesson_title}\n\n{body}", encoding="utf-8")
|
out.write_text(f"# {lesson_title}
|
||||||
|
|
||||||
|
{body}", encoding="utf-8")
|
||||||
return stem
|
return stem
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,7 +84,8 @@ async def run(community: str, output_dir: Path, discover: bool = False):
|
||||||
existing = existing_stems(output_dir)
|
existing = existing_stems(output_dir)
|
||||||
print(f"Community: {community}")
|
print(f"Community: {community}")
|
||||||
print(f"Output: {output_dir}")
|
print(f"Output: {output_dir}")
|
||||||
print(f"Lessons already saved: {len(existing)}\n")
|
print(f"Lessons already saved: {len(existing)}
|
||||||
|
")
|
||||||
|
|
||||||
async with async_playwright() as p:
|
async with async_playwright() as p:
|
||||||
browser = await p.chromium.launch(headless=False, slow_mo=25)
|
browser = await p.chromium.launch(headless=False, slow_mo=25)
|
||||||
|
|
@ -89,10 +93,12 @@ async def run(community: str, output_dir: Path, discover: bool = False):
|
||||||
page = await ctx.new_page()
|
page = await ctx.new_page()
|
||||||
|
|
||||||
print("Opening Skool — please log in when the browser window appears.")
|
print("Opening Skool — please log in when the browser window appears.")
|
||||||
print("The script will continue automatically once you land on the community.\n")
|
print("The script will continue automatically once you land on the community.
|
||||||
|
")
|
||||||
await page.goto("https://www.skool.com/login")
|
await page.goto("https://www.skool.com/login")
|
||||||
await page.wait_for_url(lambda url: f"/{community}" in url, timeout=300_000)
|
await page.wait_for_url(f"**/{community}/**", timeout=300_000)
|
||||||
print("Logged in.\n")
|
print("Logged in.
|
||||||
|
")
|
||||||
|
|
||||||
await page.goto(classroom)
|
await page.goto(classroom)
|
||||||
await page.wait_for_load_state("load")
|
await page.wait_for_load_state("load")
|
||||||
|
|
@ -101,7 +107,8 @@ async def run(community: str, output_dir: Path, discover: bool = False):
|
||||||
nd = next_data(await page.content())
|
nd = next_data(await page.content())
|
||||||
all_crses = nd.get("props", {}).get("pageProps", {}).get("allCourses", [])
|
all_crses = nd.get("props", {}).get("pageProps", {}).get("allCourses", [])
|
||||||
courses = [c for c in all_crses if c.get("metadata", {}).get("hasAccess", 0)]
|
courses = [c for c in all_crses if c.get("metadata", {}).get("hasAccess", 0)]
|
||||||
print(f"Accessible courses: {len(courses)} of {len(all_crses)} total\n")
|
print(f"Accessible courses: {len(courses)} of {len(all_crses)} total
|
||||||
|
")
|
||||||
|
|
||||||
if not courses:
|
if not courses:
|
||||||
DIAG_DIR.mkdir(parents=True, exist_ok=True)
|
DIAG_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
@ -151,7 +158,8 @@ async def run(community: str, output_dir: Path, discover: bool = False):
|
||||||
)
|
)
|
||||||
|
|
||||||
if not children:
|
if not children:
|
||||||
print(" No lessons found — skipping\n")
|
print(" No lessons found — skipping
|
||||||
|
")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f" {len(children)} lessons")
|
print(f" {len(children)} lessons")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue