26 lines
1000 B
Python
26 lines
1000 B
Python
import asyncio
|
|
from django.core.management import BaseCommand
|
|
from vacancies.main.models import RecommendedVacancy, Customer
|
|
from vacancies.main.bot import application
|
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Sends recommended vacancies to customers"
|
|
|
|
def handle(self, *args, **options):
|
|
for customer in Customer.objects.all():
|
|
recommendation = RecommendedVacancy.objects.filter(is_shown=False).first()
|
|
asyncio.run(application.bot.send_message(
|
|
chat_id=recommendation.customer.chat_id,
|
|
text=recommendation.vacancy.content,
|
|
reply_markup=InlineKeyboardMarkup([[
|
|
InlineKeyboardButton("Откликнуться", url=recommendation.vacancy.link),
|
|
]]),
|
|
))
|
|
|
|
print(recommendation.vacancy.name)
|
|
|
|
recommendation.is_shown = True
|
|
recommendation.save(update_fields=["is_shown"])
|