refactor(jobs): switch site_type param from string to SiteType enum

pull/12/head
Cullen Watson 2023-07-08 21:36:08 -05:00
parent 405842f90e
commit 9ef41979fd
1 changed files with 12 additions and 16 deletions

View File

@ -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")
@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_MAPPING = {
Site.LINKEDIN: LinkedInScraper,
Site.INDEED: IndeedScraper,
Site.ZIP_RECRUITER: 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_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