|
|
@ -15,6 +15,8 @@ from app.models.report import Report
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import config
|
|
|
|
import config
|
|
|
|
|
|
|
|
import PyRSS2Gen
|
|
|
|
|
|
|
|
import markdown
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
queue = Queue()
|
|
|
|
queue = Queue()
|
|
|
@ -146,9 +148,11 @@ def reply_comment_email(data):
|
|
|
|
# update Comment row
|
|
|
|
# update Comment row
|
|
|
|
comment.published = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
comment.published = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
comment.save()
|
|
|
|
comment.save()
|
|
|
|
|
|
|
|
|
|
|
|
logger.info('commit comment: %d' % comment_id)
|
|
|
|
logger.info('commit comment: %d' % comment_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# rebuild RSS
|
|
|
|
|
|
|
|
rss(token)
|
|
|
|
|
|
|
|
|
|
|
|
# send approval confirmation email to admin
|
|
|
|
# send approval confirmation email to admin
|
|
|
|
email_body = get_template('approve_comment').render(original=message)
|
|
|
|
email_body = get_template('approve_comment').render(original=message)
|
|
|
|
mail(from_email, 'Re: ' + subject, email_body)
|
|
|
|
mail(from_email, 'Re: ' + subject, email_body)
|
|
|
@ -334,6 +338,31 @@ def report(token):
|
|
|
|
Report.delete().execute()
|
|
|
|
Report.delete().execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rss(token):
|
|
|
|
|
|
|
|
site = Site.select().where(Site.token == token).get()
|
|
|
|
|
|
|
|
rss_title = get_template('rss_title_message').render(site=site.name)
|
|
|
|
|
|
|
|
md = markdown.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
items = []
|
|
|
|
|
|
|
|
for row in Comment.select().join(Site).where(
|
|
|
|
|
|
|
|
Site.token == token, Comment.published).order_by(-Comment.published).limit(10):
|
|
|
|
|
|
|
|
items.append(PyRSS2Gen.RSSItem(
|
|
|
|
|
|
|
|
title='%s - http://%s%s' % (row.author_name, site.url, row.url),
|
|
|
|
|
|
|
|
link="http://%s%s" % (site.url, row.url),
|
|
|
|
|
|
|
|
description=md.convert(row.content),
|
|
|
|
|
|
|
|
guid=PyRSS2Gen.Guid('%s%d' % (token, row.id)),
|
|
|
|
|
|
|
|
pubDate=row.published
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rss = PyRSS2Gen.RSS2(
|
|
|
|
|
|
|
|
title=rss_title,
|
|
|
|
|
|
|
|
link="http://" + site.url,
|
|
|
|
|
|
|
|
description="Commentaires du site '%s'" % site.name,
|
|
|
|
|
|
|
|
lastBuildDate=datetime.now(),
|
|
|
|
|
|
|
|
items=items)
|
|
|
|
|
|
|
|
rss.write_xml(open(config.RSS_FILE, "w"), encoding="utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mail(to_email, subject, message):
|
|
|
|
def mail(to_email, subject, message):
|
|
|
|
|
|
|
|
|
|
|
|
headers = {'Content-Type': 'application/json; charset=utf-8'}
|
|
|
|
headers = {'Content-Type': 'application/json; charset=utf-8'}
|
|
|
@ -368,6 +397,10 @@ def start(template_dir):
|
|
|
|
logger.info("load templates from directory %s" % template_dir)
|
|
|
|
logger.info("load templates from directory %s" % template_dir)
|
|
|
|
env = Environment(loader=FileSystemLoader(template_dir))
|
|
|
|
env = Environment(loader=FileSystemLoader(template_dir))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# generate RSS for all sites
|
|
|
|
|
|
|
|
for site in Site.select():
|
|
|
|
|
|
|
|
rss(site.token)
|
|
|
|
|
|
|
|
|
|
|
|
# start processor thread
|
|
|
|
# start processor thread
|
|
|
|
proc = Processor()
|
|
|
|
proc = Processor()
|
|
|
|
proc.start()
|
|
|
|
proc.start()
|
|
|
|