mirror of https://github.com/Bunsly/JobSpy
cleaned some code
parent
d417a3d32d
commit
bdb70ff4de
|
@ -18,32 +18,6 @@ class TelegramBot:
|
||||||
self.chatId = os.getenv("TELEGRAM_CHAT_ID")
|
self.chatId = os.getenv("TELEGRAM_CHAT_ID")
|
||||||
self.bot = Bot(token=self._api_token)
|
self.bot = Bot(token=self._api_token)
|
||||||
|
|
||||||
async def send_job(self, job: JobPost):
|
|
||||||
"""
|
|
||||||
Send JobPost details to Telegram chat.
|
|
||||||
"""
|
|
||||||
message = f"Job ID: {job.id}\n" \
|
|
||||||
f"Job Title: {job.title}\n" \
|
|
||||||
f"Company: {job.company_name}\n" \
|
|
||||||
f"Location: {job.location.display_location()}\n" \
|
|
||||||
f"Link: {job.job_url}\n"
|
|
||||||
|
|
||||||
keyboard = [
|
|
||||||
[
|
|
||||||
InlineKeyboardButton(ReactionEmoji.FIRE, callback_data=ReactionEmoji.FIRE.name),
|
|
||||||
InlineKeyboardButton(ReactionEmoji.PILE_OF_POO, callback_data=ReactionEmoji.PILE_OF_POO.name)
|
|
||||||
],
|
|
||||||
]
|
|
||||||
|
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
|
||||||
|
|
||||||
try:
|
|
||||||
await self.bot.sendMessage(chat_id=self.chatId, text=message, reply_markup=reply_markup)
|
|
||||||
logger.info(f"Sent job to Telegram: {job.id}")
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to send job to Telegram: {job.id}")
|
|
||||||
logger.error(f"Error: {e}")
|
|
||||||
|
|
||||||
def get_reply_markup(self):
|
def get_reply_markup(self):
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
|
@ -54,6 +28,24 @@ class TelegramBot:
|
||||||
|
|
||||||
return InlineKeyboardMarkup(keyboard)
|
return InlineKeyboardMarkup(keyboard)
|
||||||
|
|
||||||
|
async def send_job(self, job: JobPost):
|
||||||
|
"""
|
||||||
|
Send JobPost details to Telegram chat.
|
||||||
|
"""
|
||||||
|
message = f"Job ID: {job.id}\n" \
|
||||||
|
f"Job Title: {job.title}\n" \
|
||||||
|
f"Company: {job.company_name}\n" \
|
||||||
|
f"Location: {job.location.display_location()}\n" \
|
||||||
|
f"Link: {job.job_url}\n"
|
||||||
|
reply_markup = self.get_reply_markup()
|
||||||
|
|
||||||
|
try:
|
||||||
|
await self.bot.sendMessage(chat_id=self.chatId, text=message, reply_markup=reply_markup)
|
||||||
|
logger.info(f"Sent job to Telegram: {job.id}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to send job to Telegram: {job.id}")
|
||||||
|
logger.error(f"Error: {e}")
|
||||||
|
|
||||||
async def send_test_message(self):
|
async def send_test_message(self):
|
||||||
"""
|
"""
|
||||||
Send Test Message to Telegram chat.
|
Send Test Message to Telegram chat.
|
||||||
|
|
|
@ -6,17 +6,17 @@ from src.telegram_handler.button_callback.button_strategy import ButtonStrategy
|
||||||
|
|
||||||
|
|
||||||
class FireStrategy(ButtonStrategy):
|
class FireStrategy(ButtonStrategy):
|
||||||
def __init__(self, data: MaybeInaccessibleMessage) -> None:
|
def __init__(self, message: MaybeInaccessibleMessage) -> None:
|
||||||
"""
|
"""
|
||||||
Usually, the Context accepts a strategy through the constructor, but
|
Usually, the Context accepts a strategy through the constructor, but
|
||||||
also provides a setter to change it at runtime.
|
also provides a setter to change it at runtime.
|
||||||
"""
|
"""
|
||||||
self.data = data
|
self.message = message
|
||||||
self._emoji = ReactionEmoji.FIRE
|
self._emoji = ReactionEmoji.FIRE
|
||||||
|
self.telegram_bot = TelegramBot()
|
||||||
|
|
||||||
async def execute(self):
|
async def execute(self):
|
||||||
telegram_bot = TelegramBot()
|
await self.telegram_bot.set_message_reaction(self.message.message_id, self._emoji)
|
||||||
await telegram_bot.set_message_reaction(self.data.message_id, self._emoji)
|
|
||||||
# find the position in DB
|
# find the position in DB
|
||||||
# set applied to True
|
# set applied to True
|
||||||
# save
|
# save
|
||||||
|
|
Loading…
Reference in New Issue