mirror of https://github.com/Bunsly/JobSpy
created defualt handler and another for indeed.
on bot i can do findAll and find one by one with the command of the site namepull/231/head
parent
34e85b9261
commit
3fcc87e9b7
67
src/main.py
67
src/main.py
|
@ -3,11 +3,9 @@ import os
|
|||
from telegram import Update
|
||||
from telegram.ext import Application, CommandHandler
|
||||
|
||||
from src.jobspy import Site, scrape_jobs
|
||||
from src.jobspy.db.job_repository import JobRepository
|
||||
from src.jobspy import Site
|
||||
from src.jobspy.scrapers.utils import create_logger
|
||||
from src.telegram_bot import TelegramBot
|
||||
from src.telegram_handler import TelegramAllHandler,TelegramGoozaliHandler
|
||||
from src.telegram_handler import TelegramIndeedHandler, TelegramDefaultHandler
|
||||
|
||||
logger = create_logger("Main")
|
||||
title_filters: list[str] = ["test", "qa", "Lead", "Full-Stack", "Full Stack", "Fullstack", "Frontend", "Front-end",
|
||||
|
@ -15,46 +13,39 @@ title_filters: list[str] = ["test", "qa", "Lead", "Full-Stack", "Full Stack", "F
|
|||
"automation", "BI", "Principal", "Architect", "Android", "Machine Learning", "Student",
|
||||
"Data Engineer", "DevSecOps"]
|
||||
|
||||
|
||||
async def main():
|
||||
telegramBot = TelegramBot()
|
||||
jobRepository = JobRepository()
|
||||
# sites_to_scrap = [Site.LINKEDIN, Site.GLASSDOOR, Site.INDEED, Site.GOOZALI]
|
||||
sites_to_scrap = [Site.GOOZALI]
|
||||
# sites_to_scrap = [Site.GOOZALI]
|
||||
jobs = scrape_jobs(
|
||||
site_name=sites_to_scrap,
|
||||
search_term="software engineer",
|
||||
locations=["Tel Aviv, Israel", "Ramat Gan, Israel",
|
||||
"Central, Israel", "Rehovot ,Israel"],
|
||||
results_wanted=200,
|
||||
hours_old=48,
|
||||
country_indeed='israel'
|
||||
)
|
||||
logger.info(f"Found {len(jobs)} jobs")
|
||||
newJobs = jobRepository.insertManyIfNotFound(jobs)
|
||||
for newJob in newJobs:
|
||||
await telegramBot.sendJob(newJob)
|
||||
|
||||
|
||||
# Run the async main function
|
||||
if __name__ == "__main__":
|
||||
logger.info("Starting initialize ")
|
||||
_api_token = os.getenv("TELEGRAM_API_TOKEN")
|
||||
search_term = "software engineer"
|
||||
locations = ["Tel Aviv, Israel", "Ramat Gan, Israel", "Central, Israel", "Rehovot ,Israel"]
|
||||
application = Application.builder().token(_api_token).build()
|
||||
tg_handler_all = TelegramAllHandler(sites=[Site.LINKEDIN, Site.GLASSDOOR, Site.INDEED, Site.GOOZALI],
|
||||
locations=locations,
|
||||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
tg_handler_all = TelegramDefaultHandler(sites=[Site.LINKEDIN, Site.GLASSDOOR, Site.INDEED, Site.GOOZALI],
|
||||
locations=locations,
|
||||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
application.add_handler(CommandHandler("findAll", tg_handler_all.handle))
|
||||
tg_handler_goozali = TelegramGoozaliHandler(locations=locations,
|
||||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
application.add_handler(CommandHandler("goozali", tg_handler_goozali.handle))
|
||||
# application.add_handler(CommandHandler("galssdoor", find_glassdoor))
|
||||
# application.add_handler(CommandHandler("linkedin", find_linkedin))
|
||||
# application.add_handler(CommandHandler("indeed", find_indeed))
|
||||
# Goozali
|
||||
tg_handler_goozali = TelegramDefaultHandler(sites=[Site.GOOZALI],
|
||||
locations=locations,
|
||||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
application.add_handler(CommandHandler(Site.GOOZALI.value, tg_handler_goozali.handle))
|
||||
# GlassDoor
|
||||
tg_handler_glassdoor = TelegramDefaultHandler(sites=[Site.GLASSDOOR],
|
||||
locations=locations,
|
||||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
application.add_handler(CommandHandler(Site.GLASSDOOR.value, tg_handler_glassdoor.handle))
|
||||
# LinkeDin
|
||||
tg_handler_linkedin = TelegramDefaultHandler(sites=[Site.LINKEDIN],
|
||||
locations=locations,
|
||||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
application.add_handler(CommandHandler(Site.LINKEDIN.value, tg_handler_linkedin.handle))
|
||||
# Indeed
|
||||
tg_handler_indeed = TelegramIndeedHandler(locations=locations,
|
||||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
application.add_handler(CommandHandler(Site.INDEED.value, tg_handler_indeed.handle))
|
||||
logger.info("Run polling from telegram")
|
||||
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
from .telegram_all_handler import TelegramAllHandler
|
||||
from .telegram_goozali_handler import TelegramGoozaliHandler
|
||||
from .telegram_default_handler import TelegramDefaultHandler
|
||||
from .telegram_indeed_handler import TelegramIndeedHandler
|
||||
|
|
|
@ -9,31 +9,32 @@ from src.jobspy.scrapers.utils import create_logger
|
|||
from src.telegram_bot import TelegramBot
|
||||
from src.telegram_handler.telegram_handler import TelegramHandler
|
||||
|
||||
logger = create_logger("TelegramAllHandler")
|
||||
|
||||
|
||||
class TelegramAllHandler(TelegramHandler):
|
||||
def __init__(self, sites: list[Site], locations: list[str], title_filters: list[str],search_term:str):
|
||||
class TelegramDefaultHandler(TelegramHandler):
|
||||
def __init__(self, sites: list[Site], locations: list[str], title_filters: list[str], search_term: str):
|
||||
self.sites_to_scrap = sites
|
||||
self.locations = locations
|
||||
self.search_term = search_term
|
||||
self.title_filters = title_filters
|
||||
self.telegramBot = TelegramBot()
|
||||
self.jobRepository = JobRepository()
|
||||
if len(sites) == 1:
|
||||
self.logger = create_logger(f"Telegram{sites[0].name.title()}Handler")
|
||||
else:
|
||||
self.logger = create_logger("TelegramAllHandler")
|
||||
|
||||
async def handle(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
logger.info("start handling")
|
||||
self.logger.info("start handling")
|
||||
jobs = scrape_jobs(
|
||||
site_name=self.sites_to_scrap,
|
||||
search_term=self.search_term,
|
||||
locations=self.locations,
|
||||
results_wanted=200,
|
||||
hours_old=48,
|
||||
country_indeed='israel',
|
||||
filter_by_title=self.title_filters
|
||||
)
|
||||
logger.info(f"Found {len(jobs)} jobs")
|
||||
self.logger.info(f"Found {len(jobs)} jobs")
|
||||
new_jobs = self.jobRepository.insertManyIfNotFound(jobs)
|
||||
for newJob in new_jobs:
|
||||
await self.telegramBot.sendJob(newJob)
|
||||
logger.info("finished handling")
|
||||
self.logger.info("finished handling")
|
|
@ -9,20 +9,19 @@ from src.jobspy.scrapers.utils import create_logger
|
|||
from src.telegram_bot import TelegramBot
|
||||
from src.telegram_handler.telegram_handler import TelegramHandler
|
||||
|
||||
logger = create_logger("TelegramAllHandler")
|
||||
|
||||
|
||||
class TelegramGoozaliHandler(TelegramHandler):
|
||||
class TelegramIndeedHandler(TelegramHandler):
|
||||
def __init__(self, locations: list[str], title_filters: list[str], search_term: str):
|
||||
self.sites_to_scrap = [Site.GOOZALI]
|
||||
self.sites_to_scrap = [Site.INDEED]
|
||||
self.locations = locations
|
||||
self.search_term = search_term
|
||||
self.title_filters = title_filters
|
||||
self.telegramBot = TelegramBot()
|
||||
self.jobRepository = JobRepository()
|
||||
self.logger = create_logger(f"Telegram{self.sites_to_scrap[0].name.title()}Handler")
|
||||
|
||||
async def handle(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
logger.info("start handling")
|
||||
self.logger.info("start handling")
|
||||
jobs = scrape_jobs(
|
||||
site_name=self.sites_to_scrap,
|
||||
search_term=self.search_term,
|
||||
|
@ -32,8 +31,8 @@ class TelegramGoozaliHandler(TelegramHandler):
|
|||
country_indeed='israel',
|
||||
filter_by_title=self.title_filters
|
||||
)
|
||||
logger.info(f"Found {len(jobs)} jobs")
|
||||
self.logger.info(f"Found {len(jobs)} jobs")
|
||||
new_jobs = self.jobRepository.insertManyIfNotFound(jobs)
|
||||
for newJob in new_jobs:
|
||||
await self.telegramBot.sendJob(newJob)
|
||||
logger.info("finished handling")
|
||||
self.logger.info("finished handling")
|
Loading…
Reference in New Issue