add new param IGNORED_EMAILS and use it in cronjob
This commit is contained in:
parent
9c9ad87c7d
commit
88cef1b90d
|
@ -20,6 +20,8 @@ ADMIN_EMAIL=admin@sl.local
|
|||
MAX_NB_EMAIL_FREE_PLAN=3
|
||||
# custom domain needs to point to these MX servers
|
||||
EMAIL_SERVERS_WITH_PRIORITY=[(10, "email.hostname.")]
|
||||
# these emails are ignored when computing stats
|
||||
IGNORED_EMAILS = ["my_email@domain.com"]
|
||||
|
||||
# <<< Database >>>
|
||||
# delete and recreate sqlite database
|
||||
|
|
|
@ -52,6 +52,12 @@ EMAIL_SERVERS_WITH_PRIORITY = eval(
|
|||
) # [(10, "email.hostname.")]
|
||||
EMAIL_SERVERS = [es for _, es in EMAIL_SERVERS_WITH_PRIORITY]
|
||||
|
||||
# these emails are ignored when computing stats
|
||||
if os.environ.get("IGNORED_EMAILS"):
|
||||
IGNORED_EMAILS = eval(os.environ.get("IGNORED_EMAILS"))
|
||||
else:
|
||||
IGNORED_EMAILS = []
|
||||
|
||||
# Database
|
||||
DB_URI = os.environ["DB_URI"]
|
||||
|
||||
|
|
12
cron.py
12
cron.py
|
@ -1,6 +1,7 @@
|
|||
import arrow
|
||||
|
||||
from app import email_utils
|
||||
from app.config import IGNORED_EMAILS
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
from app.models import (
|
||||
|
@ -15,16 +16,11 @@ from app.models import (
|
|||
from server import create_app
|
||||
|
||||
|
||||
|
||||
|
||||
_ignored_emails = ["nguyenkims", "mbpcmeo", "son@simplelogin.io", "demo.simplelogin"]
|
||||
|
||||
|
||||
def stats():
|
||||
"""send admin stats everyday"""
|
||||
# nb user
|
||||
q = User.query
|
||||
for ie in _ignored_emails:
|
||||
for ie in IGNORED_EMAILS:
|
||||
q = q.filter(~User.email.contains(ie))
|
||||
|
||||
nb_user = q.count()
|
||||
|
@ -33,7 +29,7 @@ def stats():
|
|||
|
||||
# nb gen emails
|
||||
q = db.session.query(GenEmail, User).filter(GenEmail.user_id == User.id)
|
||||
for ie in _ignored_emails:
|
||||
for ie in IGNORED_EMAILS:
|
||||
q = q.filter(~User.email.contains(ie))
|
||||
|
||||
nb_gen_email = q.count()
|
||||
|
@ -45,7 +41,7 @@ def stats():
|
|||
ForwardEmail.gen_email_id == GenEmail.id,
|
||||
GenEmail.user_id == User.id,
|
||||
)
|
||||
for ie in _ignored_emails:
|
||||
for ie in IGNORED_EMAILS:
|
||||
q = q.filter(~User.email.contains(ie))
|
||||
|
||||
nb_forward = nb_block = nb_reply = 0
|
||||
|
|
Loading…
Reference in New Issue