2023-08-26 12:28:02 -07:00
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
2023-07-10 20:07:19 -07:00
|
|
|
from fastapi import APIRouter
|
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
|
2023-07-10 16:04:44 -07:00
|
|
|
from api.core.scrapers import ScraperInput, Site, JobResponse
|
2023-08-26 12:28:02 -07:00
|
|
|
from typing import List
|
2023-07-07 19:00:59 -07:00
|
|
|
|
2023-08-19 16:46:03 -07:00
|
|
|
router = APIRouter(prefix="/jobs", tags=["jobs"])
|
2023-07-07 19:00:59 -07:00
|
|
|
|
2023-07-08 19:36:08 -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
|
|
|
|
2023-08-26 12:28:02 -07:00
|
|
|
@router.post("/", response_model=List[JobResponse])
|
|
|
|
async def scrape_jobs(scraper_input: ScraperInput) -> List[JobResponse]:
|
|
|
|
def scrape_site(site: str) -> JobResponse:
|
|
|
|
scraper_class = SCRAPER_MAPPING[site]
|
|
|
|
scraper = scraper_class()
|
|
|
|
return scraper.scrape(scraper_input)
|
2023-07-08 07:34:55 -07:00
|
|
|
|
2023-08-26 12:28:02 -07:00
|
|
|
with ThreadPoolExecutor() as executor:
|
|
|
|
resp = list(executor.map(scrape_site, scraper_input.site_type))
|
2023-07-07 19:00:59 -07:00
|
|
|
|
2023-08-26 12:28:02 -07:00
|
|
|
return resp
|