# HOW TO ADD CRONJOBS
# write a cronjob function
# add cronjob to fet2020/settings.py
# add cronjob with cmd 'python3 fet2020/manage.py crontab add'
import logging
from datetime import timedelta

from django.utils import timezone

from .models import FetMeeting
from .mails import send_agenda_mail


logger = logging.getLogger(__name__)


def check_to_send_agenda_mail():
    agenda_date = timezone.now().date() + timedelta(days=2)
    next_meeting = FetMeeting.objects.filter(event_start__date=agenda_date).first()

    if next_meeting and next_meeting.has_agenda:
        logger.info(f"Agenda für die {next_meeting.slug} soll gesendet werden.")
        send_agenda_mail(next_meeting)
