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
57
src/main.py
57
src/main.py
|
@ -3,11 +3,9 @@ import os
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
from telegram.ext import Application, CommandHandler
|
from telegram.ext import Application, CommandHandler
|
||||||
|
|
||||||
from src.jobspy import Site, scrape_jobs
|
from src.jobspy import Site
|
||||||
from src.jobspy.db.job_repository import JobRepository
|
|
||||||
from src.jobspy.scrapers.utils import create_logger
|
from src.jobspy.scrapers.utils import create_logger
|
||||||
from src.telegram_bot import TelegramBot
|
from src.telegram_handler import TelegramIndeedHandler, TelegramDefaultHandler
|
||||||
from src.telegram_handler import TelegramAllHandler,TelegramGoozaliHandler
|
|
||||||
|
|
||||||
logger = create_logger("Main")
|
logger = create_logger("Main")
|
||||||
title_filters: list[str] = ["test", "qa", "Lead", "Full-Stack", "Full Stack", "Fullstack", "Frontend", "Front-end",
|
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",
|
"automation", "BI", "Principal", "Architect", "Android", "Machine Learning", "Student",
|
||||||
"Data Engineer", "DevSecOps"]
|
"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__":
|
if __name__ == "__main__":
|
||||||
logger.info("Starting initialize ")
|
logger.info("Starting initialize ")
|
||||||
_api_token = os.getenv("TELEGRAM_API_TOKEN")
|
_api_token = os.getenv("TELEGRAM_API_TOKEN")
|
||||||
search_term = "software engineer"
|
search_term = "software engineer"
|
||||||
locations = ["Tel Aviv, Israel", "Ramat Gan, Israel", "Central, Israel", "Rehovot ,Israel"]
|
locations = ["Tel Aviv, Israel", "Ramat Gan, Israel", "Central, Israel", "Rehovot ,Israel"]
|
||||||
application = Application.builder().token(_api_token).build()
|
application = Application.builder().token(_api_token).build()
|
||||||
tg_handler_all = TelegramAllHandler(sites=[Site.LINKEDIN, Site.GLASSDOOR, Site.INDEED, Site.GOOZALI],
|
tg_handler_all = TelegramDefaultHandler(sites=[Site.LINKEDIN, Site.GLASSDOOR, Site.INDEED, Site.GOOZALI],
|
||||||
locations=locations,
|
locations=locations,
|
||||||
title_filters=title_filters,
|
title_filters=title_filters,
|
||||||
search_term=search_term)
|
search_term=search_term)
|
||||||
application.add_handler(CommandHandler("findAll", tg_handler_all.handle))
|
application.add_handler(CommandHandler("findAll", tg_handler_all.handle))
|
||||||
tg_handler_goozali = TelegramGoozaliHandler(locations=locations,
|
# Goozali
|
||||||
|
tg_handler_goozali = TelegramDefaultHandler(sites=[Site.GOOZALI],
|
||||||
|
locations=locations,
|
||||||
title_filters=title_filters,
|
title_filters=title_filters,
|
||||||
search_term=search_term)
|
search_term=search_term)
|
||||||
application.add_handler(CommandHandler("goozali", tg_handler_goozali.handle))
|
application.add_handler(CommandHandler(Site.GOOZALI.value, tg_handler_goozali.handle))
|
||||||
# application.add_handler(CommandHandler("galssdoor", find_glassdoor))
|
# GlassDoor
|
||||||
# application.add_handler(CommandHandler("linkedin", find_linkedin))
|
tg_handler_glassdoor = TelegramDefaultHandler(sites=[Site.GLASSDOOR],
|
||||||
# application.add_handler(CommandHandler("indeed", find_indeed))
|
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")
|
logger.info("Run polling from telegram")
|
||||||
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
from .telegram_all_handler import TelegramAllHandler
|
from .telegram_default_handler import TelegramDefaultHandler
|
||||||
from .telegram_goozali_handler import TelegramGoozaliHandler
|
from .telegram_indeed_handler import TelegramIndeedHandler
|
||||||
|
|
|
@ -9,10 +9,8 @@ from src.jobspy.scrapers.utils import create_logger
|
||||||
from src.telegram_bot import TelegramBot
|
from src.telegram_bot import TelegramBot
|
||||||
from src.telegram_handler.telegram_handler import TelegramHandler
|
from src.telegram_handler.telegram_handler import TelegramHandler
|
||||||
|
|
||||||
logger = create_logger("TelegramAllHandler")
|
|
||||||
|
|
||||||
|
class TelegramDefaultHandler(TelegramHandler):
|
||||||
class TelegramAllHandler(TelegramHandler):
|
|
||||||
def __init__(self, sites: list[Site], locations: list[str], title_filters: list[str], search_term: str):
|
def __init__(self, sites: list[Site], locations: list[str], title_filters: list[str], search_term: str):
|
||||||
self.sites_to_scrap = sites
|
self.sites_to_scrap = sites
|
||||||
self.locations = locations
|
self.locations = locations
|
||||||
|
@ -20,20 +18,23 @@ class TelegramAllHandler(TelegramHandler):
|
||||||
self.title_filters = title_filters
|
self.title_filters = title_filters
|
||||||
self.telegramBot = TelegramBot()
|
self.telegramBot = TelegramBot()
|
||||||
self.jobRepository = JobRepository()
|
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):
|
async def handle(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
logger.info("start handling")
|
self.logger.info("start handling")
|
||||||
jobs = scrape_jobs(
|
jobs = scrape_jobs(
|
||||||
site_name=self.sites_to_scrap,
|
site_name=self.sites_to_scrap,
|
||||||
search_term=self.search_term,
|
search_term=self.search_term,
|
||||||
locations=self.locations,
|
locations=self.locations,
|
||||||
results_wanted=200,
|
results_wanted=200,
|
||||||
hours_old=48,
|
hours_old=48,
|
||||||
country_indeed='israel',
|
|
||||||
filter_by_title=self.title_filters
|
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)
|
new_jobs = self.jobRepository.insertManyIfNotFound(jobs)
|
||||||
for newJob in new_jobs:
|
for newJob in new_jobs:
|
||||||
await self.telegramBot.sendJob(newJob)
|
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_bot import TelegramBot
|
||||||
from src.telegram_handler.telegram_handler import TelegramHandler
|
from src.telegram_handler.telegram_handler import TelegramHandler
|
||||||
|
|
||||||
logger = create_logger("TelegramAllHandler")
|
|
||||||
|
|
||||||
|
class TelegramIndeedHandler(TelegramHandler):
|
||||||
class TelegramGoozaliHandler(TelegramHandler):
|
|
||||||
def __init__(self, locations: list[str], title_filters: list[str], search_term: str):
|
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.locations = locations
|
||||||
self.search_term = search_term
|
self.search_term = search_term
|
||||||
self.title_filters = title_filters
|
self.title_filters = title_filters
|
||||||
self.telegramBot = TelegramBot()
|
self.telegramBot = TelegramBot()
|
||||||
self.jobRepository = JobRepository()
|
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):
|
async def handle(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
logger.info("start handling")
|
self.logger.info("start handling")
|
||||||
jobs = scrape_jobs(
|
jobs = scrape_jobs(
|
||||||
site_name=self.sites_to_scrap,
|
site_name=self.sites_to_scrap,
|
||||||
search_term=self.search_term,
|
search_term=self.search_term,
|
||||||
|
@ -32,8 +31,8 @@ class TelegramGoozaliHandler(TelegramHandler):
|
||||||
country_indeed='israel',
|
country_indeed='israel',
|
||||||
filter_by_title=self.title_filters
|
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)
|
new_jobs = self.jobRepository.insertManyIfNotFound(jobs)
|
||||||
for newJob in new_jobs:
|
for newJob in new_jobs:
|
||||||
await self.telegramBot.sendJob(newJob)
|
await self.telegramBot.sendJob(newJob)
|
||||||
logger.info("finished handling")
|
self.logger.info("finished handling")
|
Loading…
Reference in New Issue