mirror of https://github.com/Bunsly/JobSpy
fixed location string to be more readable and adde telegram test
parent
d6655676f3
commit
f1c39e47bd
|
@ -25,7 +25,7 @@ async def main():
|
|||
new_jobs = jobRepository.insertManyIfNotFound(jobs)
|
||||
|
||||
for new_job in new_jobs:
|
||||
await telegramBot.send_job(new_job)
|
||||
await telegramBot.sendJob(new_job)
|
||||
|
||||
# Run the async main function
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -14,7 +14,7 @@ class TelegramBot:
|
|||
self.chatId = os.getenv("TELEGRAM_CHAT_ID")
|
||||
self.bot = Bot(token=self._api_token)
|
||||
|
||||
async def send_job(self, job: JobPost):
|
||||
async def sendJob(self, job: JobPost):
|
||||
"""
|
||||
Send JobPost details to Telegram chat.
|
||||
"""
|
||||
|
@ -22,7 +22,7 @@ class TelegramBot:
|
|||
f"Job ID: {job.id}\n" \
|
||||
f"Job Title: {job.title}\n" \
|
||||
f"Company: {job.company_name}\n" \
|
||||
f"Location: {job.location}\n" \
|
||||
f"Location: {job.location.display_location()}\n" \
|
||||
f"Link: {job.job_url}\n"
|
||||
try:
|
||||
await self.bot.sendMessage(chat_id=self.chatId, text=message)
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import asyncio
|
||||
from dotenv import load_dotenv
|
||||
from jobspy.db.job_repository import JobRepository
|
||||
from jobspy.telegram_bot import TelegramBot
|
||||
from tests.test_util import createMockJob
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class TelegramTests:
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
This block ensures that the script runs the test only when executed directly,
|
||||
not when imported as a module.
|
||||
"""
|
||||
self.bot = TelegramBot()
|
||||
|
||||
async def send_job(self):
|
||||
"""
|
||||
Sents a mock job Telegram using Telegram Bot.
|
||||
"""
|
||||
job = createMockJob()
|
||||
await self.bot.sendJob(job)
|
||||
print(f"Test sent job finished.")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Create an instance of DatabaseTests
|
||||
tests = TelegramTests()
|
||||
|
||||
# Run the send_job test
|
||||
asyncio.run(tests.send_job())
|
Loading…
Reference in New Issue