JobSpy/api/v1/jobs/__init__.py

27 lines
879 B
Python
Raw Normal View History

2023-07-09 13:15:39 -07:00
from fastapi import APIRouter, Depends
2023-07-06 16:44:38 -07:00
2023-07-07 19:00:59 -07:00
from api.core.scrapers.indeed import IndeedScraper
2023-07-08 04:57:36 -07:00
from api.core.scrapers.ziprecruiter import ZipRecruiterScraper
2023-07-08 07:34:55 -07:00
from api.core.scrapers.linkedin import LinkedInScraper
from api.core.scrapers import ScraperInput, Site
2023-07-09 13:15:39 -07:00
from ...v1.token.auth import get_active_current_user
2023-07-07 19:00:59 -07:00
2023-07-09 13:15:39 -07:00
router = APIRouter(prefix="/jobs", dependencies=[Depends(get_active_current_user)])
2023-07-07 19:00:59 -07:00
SCRAPER_MAPPING = {
Site.LINKEDIN: LinkedInScraper,
Site.INDEED: IndeedScraper,
Site.ZIP_RECRUITER: ZipRecruiterScraper,
}
2023-07-07 19:00:59 -07:00
2023-07-08 07:34:55 -07:00
@router.get("/")
async def scrape_jobs(site_type: Site, search_term: str, location: str, page: int = 1):
scraper_class = SCRAPER_MAPPING[site_type]
scraper = scraper_class()
2023-07-08 07:34:55 -07:00
scraper_input = ScraperInput(search_term=search_term, location=location, page=page)
job_response = scraper.scrape(scraper_input)
2023-07-07 19:00:59 -07:00
return job_response