microservicified
This commit is contained in:
parent
8311053d08
commit
ec86069ec7
5 changed files with 20 additions and 14 deletions
|
@ -42,7 +42,7 @@ Stacosys can be hosted on the same server or on a different server than the blog
|
||||||
|
|
||||||
Python 3.7
|
Python 3.7
|
||||||
|
|
||||||
pip libs: flask peewee pyrss2gen markdown clize flask-apscheduler profig
|
pip libs: flask peewee pyrss2gen markdown clize flask-apscheduler profig requests
|
||||||
|
|
||||||
### Ways of improvement
|
### Ways of improvement
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,11 @@ def cron(func):
|
||||||
def fetch_mail_answers():
|
def fetch_mail_answers():
|
||||||
|
|
||||||
for msg in mailer.fetch():
|
for msg in mailer.fetch():
|
||||||
m = re.search(r"\[(\d+)\:(\w+)\]", msg["subject"])
|
if re.search(r".*STACOSYS.*\[(\d+)\:(\w+)\]", msg["subject"], re.DOTALL):
|
||||||
if m:
|
|
||||||
full_msg = mailer.get(msg["id"])
|
full_msg = mailer.get(msg["id"])
|
||||||
if full_msg:
|
if full_msg and reply_comment_email(full_msg['email']):
|
||||||
reply_comment_email(full_msg)
|
|
||||||
mailer.delete(msg["id"])
|
mailer.delete(msg["id"])
|
||||||
|
|
||||||
|
|
||||||
@cron
|
@cron
|
||||||
def submit_new_comment():
|
def submit_new_comment():
|
||||||
|
|
||||||
|
@ -42,10 +39,10 @@ def submit_new_comment():
|
||||||
comment_list = (
|
comment_list = (
|
||||||
"author: %s" % comment.author_name,
|
"author: %s" % comment.author_name,
|
||||||
"site: %s" % comment.author_site,
|
"site: %s" % comment.author_site,
|
||||||
"date: %s" % comment.create,
|
"date: %s" % comment.created,
|
||||||
"url: %s" % comment.url,
|
"url: %s" % comment.url,
|
||||||
"",
|
"",
|
||||||
"%s" % comment.message,
|
"%s" % comment.content,
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
comment_text = "\n".join(comment_list)
|
comment_text = "\n".join(comment_list)
|
||||||
|
@ -54,11 +51,15 @@ def submit_new_comment():
|
||||||
)
|
)
|
||||||
|
|
||||||
# send email
|
# send email
|
||||||
site = Site.select().where(Site.id == Comment.site).get()
|
site = Site.get(Site.id == comment.site)
|
||||||
subject = "STACOSYS %s: [%d:%s]" % (site.name, comment.id, site.token)
|
subject = "STACOSYS %s: [%d:%s]" % (site.name, comment.id, site.token)
|
||||||
mailer.send(site.admin_email, subject, email_body)
|
mailer.send(site.admin_email, subject, email_body)
|
||||||
logger.debug("new comment processed ")
|
logger.debug("new comment processed ")
|
||||||
|
|
||||||
|
# update comment
|
||||||
|
comment.notified = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
comment.save()
|
||||||
|
|
||||||
|
|
||||||
def reply_comment_email(data):
|
def reply_comment_email(data):
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ def reply_comment_email(data):
|
||||||
comment = Comment.select().where(Comment.id == comment_id).get()
|
comment = Comment.select().where(Comment.id == comment_id).get()
|
||||||
except:
|
except:
|
||||||
logger.warn("unknown comment %d" % comment_id)
|
logger.warn("unknown comment %d" % comment_id)
|
||||||
return
|
return True
|
||||||
|
|
||||||
if comment.published:
|
if comment.published:
|
||||||
logger.warn("ignore already published email. token %d" % comment_id)
|
logger.warn("ignore already published email. token %d" % comment_id)
|
||||||
|
@ -103,7 +104,7 @@ def reply_comment_email(data):
|
||||||
if message[:2].upper() == "SP": # SPAM
|
if message[:2].upper() == "SP": # SPAM
|
||||||
if comment.ip:
|
if comment.ip:
|
||||||
logger.info(
|
logger.info(
|
||||||
"SPAM comment from %s: %d" % (client_ips[comment_id], comment_id)
|
"SPAM comment from %s: %d" % (comment.ip, comment_id)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.info("cannot identify SPAM source: %d" % comment_id)
|
logger.info("cannot identify SPAM source: %d" % comment_id)
|
||||||
|
@ -126,3 +127,4 @@ def reply_comment_email(data):
|
||||||
email_body = get_template("approve_comment").render(original=message)
|
email_body = get_template("approve_comment").render(original=message)
|
||||||
mailer.send(from_email, "Re: " + subject, email_body)
|
mailer.send(from_email, "Re: " + subject, email_body)
|
||||||
|
|
||||||
|
return True
|
|
@ -22,7 +22,7 @@ def fetch():
|
||||||
|
|
||||||
def get(id):
|
def get(id):
|
||||||
payload = None
|
payload = None
|
||||||
r = requests.get(config.get(config.MAILER_URL) + "/mbox/" + id)
|
r = requests.get(config.get(config.MAILER_URL) + "/mbox/" + str(id))
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
payload = r.json()
|
payload = r.json()
|
||||||
return payload
|
return payload
|
||||||
|
@ -41,4 +41,4 @@ def send(to_email, subject, message):
|
||||||
|
|
||||||
|
|
||||||
def delete(id):
|
def delete(id):
|
||||||
requests.delete(config.get(config.MAILER_URL) + "/mbox/" + id)
|
requests.delete(config.get(config.MAILER_URL) + "/mbox/" + str(id))
|
||||||
|
|
|
@ -42,7 +42,7 @@ def new_form_comment():
|
||||||
url = data.get("url", "")
|
url = data.get("url", "")
|
||||||
author_name = data.get("author", "").strip()
|
author_name = data.get("author", "").strip()
|
||||||
author_gravatar = data.get("email", "").strip()
|
author_gravatar = data.get("email", "").strip()
|
||||||
author_site = data.get("site", "").to_lower().strip()
|
author_site = data.get("site", "").lower().strip()
|
||||||
if author_site and author_site[:4] != "http":
|
if author_site and author_site[:4] != "http":
|
||||||
author_site = "http://" + author_site
|
author_site = "http://" + author_site
|
||||||
message = data.get("message", "")
|
message = data.get("message", "")
|
||||||
|
|
|
@ -26,6 +26,10 @@ class JobConfig(object):
|
||||||
|
|
||||||
JOBS = []
|
JOBS = []
|
||||||
|
|
||||||
|
SCHEDULER_EXECUTORS = {
|
||||||
|
'default': {'type': 'threadpool', 'max_workers': 20}
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, mail_polling_seconds, new_comment_polling_seconds):
|
def __init__(self, mail_polling_seconds, new_comment_polling_seconds):
|
||||||
self.JOBS = [
|
self.JOBS = [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue