mirror of https://github.com/Bunsly/JobSpy
extracted button call back
parent
f71bb91b68
commit
8996c59492
|
@ -6,6 +6,7 @@ from telegram.ext import Application, CommandHandler, CallbackQueryHandler
|
|||
from src.jobspy import Site
|
||||
from src.jobspy.scrapers.utils import create_logger
|
||||
from src.telegram_handler import TelegramIndeedHandler, TelegramDefaultHandler
|
||||
from src.telegram_handler.telegram_callback_handler import TelegramCallHandler
|
||||
|
||||
logger = create_logger("Main")
|
||||
title_filters: list[str] = ["test", "qa", "Lead", "Full-Stack", "Full Stack", "Fullstack", "Frontend", "Front-end",
|
||||
|
@ -19,6 +20,7 @@ if __name__ == "__main__":
|
|||
search_term = "software engineer"
|
||||
locations = ["Tel Aviv, Israel", "Ramat Gan, Israel", "Central, Israel", "Rehovot ,Israel"]
|
||||
application = Application.builder().token(_api_token).build()
|
||||
tg_callback_handler = TelegramCallHandler()
|
||||
tg_handler_all = TelegramDefaultHandler(sites=[Site.LINKEDIN, Site.GLASSDOOR, Site.INDEED, Site.GOOZALI],
|
||||
locations=locations,
|
||||
title_filters=title_filters,
|
||||
|
@ -47,6 +49,6 @@ if __name__ == "__main__":
|
|||
title_filters=title_filters,
|
||||
search_term=search_term)
|
||||
application.add_handler(CommandHandler(Site.INDEED.value, tg_handler_indeed.handle))
|
||||
application.add_handler(CallbackQueryHandler(tg_handler_linkedin.button))
|
||||
application.add_handler(CallbackQueryHandler(tg_callback_handler.button_callback))
|
||||
logger.info("Run polling from telegram")
|
||||
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
from telegram import Update
|
||||
from telegram.ext import (
|
||||
ContextTypes,
|
||||
)
|
||||
|
||||
from src.telegram_bot import TelegramBot
|
||||
|
||||
|
||||
class TelegramCallHandler:
|
||||
def __init__(self):
|
||||
self.telegram_bot = TelegramBot()
|
||||
|
||||
async def button_callback(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Parses the CallbackQuery and updates the message text."""
|
||||
query = update.callback_query
|
||||
|
||||
# CallbackQueries need to be answered, even if no notification to the user is needed
|
||||
# Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
|
||||
await query.answer()
|
||||
await self.telegram_bot.set_message_reaction(query.message.message_id, query.data)
|
||||
|
|
@ -23,15 +23,6 @@ class TelegramDefaultHandler(TelegramHandler):
|
|||
else:
|
||||
self.logger = create_logger("TelegramAllHandler")
|
||||
|
||||
async def button(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Parses the CallbackQuery and updates the message text."""
|
||||
query = update.callback_query
|
||||
|
||||
# CallbackQueries need to be answered, even if no notification to the user is needed
|
||||
# Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
|
||||
await query.answer()
|
||||
await self.telegram_bot.set_message_reaction(query.message.message_id, query.data)
|
||||
|
||||
async def handle(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
self.logger.info("start handling")
|
||||
jobs = scrape_jobs(
|
||||
|
|
Loading…
Reference in New Issue