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.indeed import IndeedScraper
|
||||||
from api.core.scrapers.ziprecruiter import ZipRecruiterScraper
|
from api.core.scrapers.ziprecruiter import ZipRecruiterScraper
|
||||||
from api.core.scrapers.linkedin import LinkedInScraper
|
from api.core.scrapers.linkedin import LinkedInScraper
|
||||||
from api.core.scrapers import ScraperInput
|
from api.core.scrapers import ScraperInput, Site
|
||||||
|
|
||||||
router = APIRouter(prefix="/jobs")
|
router = APIRouter(prefix="/jobs")
|
||||||
|
|
||||||
|
SCRAPER_MAPPING = {
|
||||||
@router.get("/")
|
Site.LINKEDIN: LinkedInScraper,
|
||||||
async def scrape_jobs(site_type: str, search_term: str, location: str, page: int = 1):
|
Site.INDEED: IndeedScraper,
|
||||||
job_response = {"message": "site type not found"}
|
Site.ZIP_RECRUITER: ZipRecruiterScraper,
|
||||||
|
|
||||||
scraper_dict = {
|
|
||||||
"indeed": IndeedScraper,
|
|
||||||
"linkedin": LinkedInScraper,
|
|
||||||
"zip": ZipRecruiterScraper,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scraper_class = scraper_dict.get(site_type)
|
|
||||||
if scraper_class:
|
@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()
|
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)
|
job_response = scraper.scrape(scraper_input)
|
||||||
|
|
||||||
return job_response
|
return job_response
|
||||||
|
|
Loading…
Reference in New Issue