You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stacosys/app/core/cron.py

48 lines
1.3 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import time
from core import app
from core import processor
from models.comment import Comment
logger = logging.getLogger(__name__)
def fetch_mail_answers():
logger.info('DEBUT POP MAIL')
time.sleep(80)
logger.info('FIN POP MAIL')
#data = request.get_json()
#logger.debug(data)
#processor.enqueue({'request': 'new_mail', 'data': data})
def submit_new_comment():
for comment in Comment.select().where(Comment.notified.is_null()):
# render email body template
comment_list = (
"author: %s" % comment.author_name,
"site: %s" % comment.author_site,
"date: %s" % comment.create,
"url: %s" % comment.url,
"",
"%s" % comment.message,
"",
)
comment_text = "\n".join(comment_list)
email_body = get_template("new_comment").render(url=url, comment=comment_text)
if clientip:
client_ips[comment.id] = clientip
# send email
subject = "STACOSYS %s: [%d:%s]" % (site.name, comment.id, token)
mailer.send_mail(site.admin_email, subject, email_body)
logger.debug("new comment processed ")
def get_template(name):
return env.get_template(config.general["lang"] + "/" + name + ".tpl")