mirror of https://github.com/Bunsly/JobSpy
refactor(jobs): switch site_type param from string to SiteType enum
parent
405842f90e
commit
9ef41979fd
|
@ -3,27 +3,23 @@ from fastapi import APIRouter
|
|||
from api.core.scrapers.indeed import IndeedScraper
|
||||
from api.core.scrapers.ziprecruiter import ZipRecruiterScraper
|
||||
from api.core.scrapers.linkedin import LinkedInScraper
|
||||
from api.core.scrapers import ScraperInput
|
||||
from api.core.scrapers import ScraperInput, Site
|
||||
|
||||
router = APIRouter(prefix="/jobs")
|
||||
|
||||
SCRAPER_MAPPING = {
|
||||
Site.LINKEDIN: LinkedInScraper,
|
||||
Site.INDEED: IndeedScraper,
|
||||
Site.ZIP_RECRUITER: ZipRecruiterScraper,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def scrape_jobs(site_type: str, search_term: str, location: str, page: int = 1):
|
||||
job_response = {"message": "site type not found"}
|
||||
|
||||
scraper_dict = {
|
||||
"indeed": IndeedScraper,
|
||||
"linkedin": LinkedInScraper,
|
||||
"zip": ZipRecruiterScraper,
|
||||
}
|
||||
|
||||
scraper_class = scraper_dict.get(site_type)
|
||||
if scraper_class:
|
||||
async def scrape_jobs(site_type: Site, search_term: str, location: str, page: int = 1):
|
||||
scraper_class = SCRAPER_MAPPING[site_type]
|
||||
scraper = scraper_class()
|
||||
scraper_input = ScraperInput(
|
||||
search_term=search_term, location=location, page=page
|
||||
)
|
||||
|
||||
scraper_input = ScraperInput(search_term=search_term, location=location, page=page)
|
||||
job_response = scraper.scrape(scraper_input)
|
||||
|
||||
return job_response
|
||||
|
|
Loading…
Reference in New Issue