UdemyScout / scraper /batch_meta.py
Brainw's picture
Upload 14 files
248a83c verified
Raw History Blame Contribute Delete
500 Bytes
import httpx
import asyncio
from scraper.course_meta import fetch_course_meta, HEADERS
async def fetch_meta_batch(courses, limit=8):
sem = asyncio.Semaphore(limit)
async with httpx.AsyncClient(headers=HEADERS, timeout=10, follow_redirects=True) as client:
async def safe(c):
async with sem:
meta = await fetch_course_meta(client, c["url"])
return {**c, **meta}
return await asyncio.gather(*[safe(c) for c in courses])