microservicified
This commit is contained in:
parent
2554c716da
commit
564c27a00a
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
|
||||
|
||||
pip libs: flask peewee pyrss2gen markdown clize flask-apscheduler profig
|
||||
pip libs: flask peewee pyrss2gen markdown clize flask-apscheduler profig requests
|
||||
|
||||
### Ways of improvement
|
||||
|
||||
|
|
|
@ -26,14 +26,11 @@ def cron(func):
|
|||
def fetch_mail_answers():
|
||||
|
||||
for msg in mailer.fetch():
|
||||
m = re.search(r"\[(\d+)\:(\w+)\]", msg["subject"])
|
||||
if m:
|
||||
if re.search(r".*STACOSYS.*\[(\d+)\:(\w+)\]", msg["subject"], re.DOTALL):
|
||||
full_msg = mailer.get(msg["id"])
|
||||
if full_msg:
|
||||
reply_comment_email(full_msg)
|
||||
if full_msg and reply_comment_email(full_msg['email']):
|
||||
mailer.delete(msg["id"])
|
||||
|
||||
|
||||
@cron
|
||||
def submit_new_comment():
|
||||
|
||||
|
@ -42,10 +39,10 @@ def submit_new_comment():
|
|||
comment_list = (
|
||||
"author: %s" % comment.author_name,
|
||||
"site: %s" % comment.author_site,
|
||||
"date: %s" % comment.create,
|
||||
"date: %s" % comment.created,
|
||||
"url: %s" % comment.url,
|
||||
"",
|
||||
"%s" % comment.message,
|
||||
"%s" % comment.content,
|
||||
"",
|
||||
)
|
||||
comment_text = "\n".join(comment_list)
|
||||
|
@ -54,11 +51,15 @@ def submit_new_comment():
|
|||
)
|
||||
|
||||
# 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)
|
||||
mailer.send(site.admin_email, subject, email_body)
|
||||
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):
|
||||
|
||||
|
@ -82,7 +83,7 @@ def reply_comment_email(data):
|
|||
comment = Comment.select().where(Comment.id == comment_id).get()
|
||||
except:
|
||||
logger.warn("unknown comment %d" % comment_id)
|
||||
return
|
||||
return True
|
||||
|
||||
if comment.published:
|
||||
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 comment.ip:
|
||||
logger.info(
|
||||
"SPAM comment from %s: %d" % (client_ips[comment_id], comment_id)
|
||||
"SPAM comment from %s: %d" % (comment.ip, comment_id)
|
||||
)
|
||||
else:
|
||||
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)
|
||||
mailer.send(from_email, "Re: " + subject, email_body)
|
||||
|
||||
return True
|
|
@ -22,7 +22,7 @@ def fetch():
|
|||
|
||||
def get(id):
|
||||
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:
|
||||
payload = r.json()
|
||||
return payload
|
||||
|
@ -41,4 +41,4 @@ def send(to_email, subject, message):
|
|||
|
||||
|
||||
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", "")
|
||||
author_name = data.get("author", "").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":
|
||||
author_site = "http://" + author_site
|
||||
message = data.get("message", "")
|
||||
|
|
|
@ -26,6 +26,10 @@ class JobConfig(object):
|
|||
|
||||
JOBS = []
|
||||
|
||||
SCHEDULER_EXECUTORS = {
|
||||
'default': {'type': 'threadpool', 'max_workers': 20}
|
||||
}
|
||||
|
||||
def __init__(self, mail_polling_seconds, new_comment_polling_seconds):
|
||||
self.JOBS = [
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue