|
|
@ -6,7 +6,8 @@ import re
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import datetime
|
|
|
|
from threading import Thread
|
|
|
|
from threading import Thread
|
|
|
|
from queue import Queue
|
|
|
|
from queue import Queue
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
from jinja2 import Environment
|
|
|
|
|
|
|
|
from jinja2 import FileSystemLoader
|
|
|
|
from app.models.site import Site
|
|
|
|
from app.models.site import Site
|
|
|
|
from app.models.comment import Comment
|
|
|
|
from app.models.comment import Comment
|
|
|
|
from app.models.reader import Reader
|
|
|
|
from app.models.reader import Reader
|
|
|
@ -15,7 +16,6 @@ import requests
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import config
|
|
|
|
import config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
queue = Queue()
|
|
|
|
queue = Queue()
|
|
|
|
proc = None
|
|
|
|
proc = None
|
|
|
@ -206,8 +206,8 @@ def notify_subscribed_readers(token, site_url, url):
|
|
|
|
Reader.url == url):
|
|
|
|
Reader.url == url):
|
|
|
|
to_email = reader.email
|
|
|
|
to_email = reader.email
|
|
|
|
logger.info('notify reader %s' % to_email)
|
|
|
|
logger.info('notify reader %s' % to_email)
|
|
|
|
unsubscribe_url = '%s?email=%s&token=%s&url=%s' % (
|
|
|
|
unsubscribe_url = '%s/unsubscribe?email=%s&token=%s&url=%s' % (
|
|
|
|
config.UNSUBSCRIBE_URL, to_email, token, reader.url)
|
|
|
|
config.ROOT_URL, to_email, token, reader.url)
|
|
|
|
email_body = get_template(
|
|
|
|
email_body = get_template(
|
|
|
|
'notify_subscriber').render(article_url=article_url,
|
|
|
|
'notify_subscriber').render(article_url=article_url,
|
|
|
|
unsubscribe_url=unsubscribe_url)
|
|
|
|
unsubscribe_url=unsubscribe_url)
|
|
|
@ -253,25 +253,53 @@ def report_unsubscribed(comment):
|
|
|
|
|
|
|
|
|
|
|
|
def report(token):
|
|
|
|
def report(token):
|
|
|
|
site = Site.select().where(Site.token == token).get()
|
|
|
|
site = Site.select().where(Site.token == token).get()
|
|
|
|
c_standby = Comment.select().join(Site).where(
|
|
|
|
|
|
|
|
Site.token == token, Comment.published.is_null(True)).count()
|
|
|
|
standbys = []
|
|
|
|
c_published = Report.select().join(Site).where(
|
|
|
|
for row in Comment.select().join(Site).where(
|
|
|
|
Site.token == token, Report.published).count()
|
|
|
|
Site.token == token, Comment.published.is_null(True)):
|
|
|
|
c_rejected = Report.select().join(Site).where(
|
|
|
|
standbys.append({'url': "http://" + site.url + row.url,
|
|
|
|
Site.token == token, Report.rejected).count()
|
|
|
|
'created': row.created.strftime('%d/%m/%y %H:%M'),
|
|
|
|
c_subscribed = Report.select().join(Site).where(
|
|
|
|
'name': row.author_name, 'content': row.content,
|
|
|
|
Site.token == token, Report.subscribed).count()
|
|
|
|
'id': row.id})
|
|
|
|
c_unsubscribed = Report.select().join(Site).where(
|
|
|
|
|
|
|
|
Site.token == token, Report.unsubscribed).count()
|
|
|
|
published = []
|
|
|
|
email_body = get_template('report').render(standby=c_standby, published=c_published, rejected=c_rejected,
|
|
|
|
for row in Report.select().join(Site).where(
|
|
|
|
subscribed=c_subscribed,unsubscribed=c_unsubscribed)
|
|
|
|
Site.token == token, Report.published):
|
|
|
|
|
|
|
|
published.append({'url': "http://" + site.url + row.url,
|
|
|
|
|
|
|
|
'name': row.name, 'email': row.email})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rejected = []
|
|
|
|
|
|
|
|
for row in Report.select().join(Site).where(
|
|
|
|
|
|
|
|
Site.token == token, Report.rejected):
|
|
|
|
|
|
|
|
rejected.append({'url': "http://" + site.url + row.url,
|
|
|
|
|
|
|
|
'name': row.name, 'email': row.email})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subscribed = []
|
|
|
|
|
|
|
|
for row in Report.select().join(Site).where(
|
|
|
|
|
|
|
|
Site.token == token, Report.subscribed):
|
|
|
|
|
|
|
|
subscribed.append({'url': "http://" + site.url + row.url,
|
|
|
|
|
|
|
|
'name': row.name, 'email': row.email})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsubscribed = []
|
|
|
|
|
|
|
|
for row in Report.select().join(Site).where(
|
|
|
|
|
|
|
|
Site.token == token, Report.subscribed):
|
|
|
|
|
|
|
|
unsubscribed.append({'url': "http://" + site.url + row.url,
|
|
|
|
|
|
|
|
'name': row.name, 'email': row.email})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
email_body = get_template('report').render(secret=config.SECRET,
|
|
|
|
|
|
|
|
root_url=config.ROOT_URL,
|
|
|
|
|
|
|
|
standbys=standbys,
|
|
|
|
|
|
|
|
published=published,
|
|
|
|
|
|
|
|
rejected=rejected,
|
|
|
|
|
|
|
|
subscribed=subscribed,
|
|
|
|
|
|
|
|
unsubscribed=unsubscribed)
|
|
|
|
subject = get_template('report_message').render(site=site.name)
|
|
|
|
subject = get_template('report_message').render(site=site.name)
|
|
|
|
mail(site.admin_email, subject, email_body)
|
|
|
|
print(email_body)
|
|
|
|
|
|
|
|
#mail(site.admin_email, subject, email_body)
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: delete report table
|
|
|
|
# TODO: delete report table
|
|
|
|
# Report.delete().execute()
|
|
|
|
# Report.delete().execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'}
|
|
|
|