41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
|
import logging
|
||
|
import os
|
||
|
import tempfile
|
||
|
|
||
|
from celery.schedules import crontab
|
||
|
from django.conf import settings
|
||
|
from django.utils import timezone
|
||
|
|
||
|
from . import utils
|
||
|
from ..signalbot import rpc
|
||
|
from ..item import view
|
||
|
from ..item import models
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
@app.task(queue="default", ignore_results=True)
|
||
|
def send_week():
|
||
|
now = views.get_now()
|
||
|
if now.hour < 15:
|
||
|
return
|
||
|
monday = views.get_monday(now)
|
||
|
week, archive = models.Item.public(now)
|
||
|
week_obj = models.Week.objects.filter(monday=monday).first()
|
||
|
if not week_obj:
|
||
|
message = "no title for week, can not send out email please add: %s/admin/item/week/add/?monday=%s" % (settings.URL, monday)
|
||
|
r = rpc.send(message, group=settings.SIGNAL_MODERATORS_GROUP)
|
||
|
elif week.filter(announced=None).exists():
|
||
|
logger.error("waiting for last item of the week to be public")
|
||
|
elif not week_obj.published:
|
||
|
monday = views.get_monday(now)
|
||
|
week_obj.published = now
|
||
|
week_obj.save()
|
||
|
if not utils.send_week(monday):
|
||
|
message = "weekly newsletter ready, confirm at https://list.phantas.ma/admin/campaigns"
|
||
|
r = rpc.send(message, group=settings.SIGNAL_MODERATORS_GROUP)
|
||
|
|
||
|
|
||
|
@app.on_after_finalize.connect
|
||
|
def setup_periodic_tasks(sender, **kwargs):
|
||
|
sender.add_periodic_task(crontab(day_of_week=0, minute="*/30"), send_week.s())
|