Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 72a60b4

Browse files
committed
scaffolding for daily email
1 parent c9ea8bd commit 72a60b4

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

CodeChallenge/api/eb.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
from flask import Blueprint
1+
from hmac import compare_digest
2+
3+
from flask import Blueprint, request, current_app, render_template
4+
from flask_mail import Message
5+
6+
from .. import core
7+
from ..mail import mail
28

39
bp = Blueprint("awsebapi", __name__, url_prefix="/api/v1/eb")
410

@@ -7,3 +13,30 @@
713
@bp.route("/health", methods=["GET"])
814
def eb_health_check():
915
return "OK", 200
16+
17+
18+
# POST request from an AWS Lambda function once per day
19+
# any daily tasks should be placed here
20+
@bp.route("/worker", methods=["POST"])
21+
def worker():
22+
try:
23+
password = request.json["password"]
24+
except (TypeError, KeyError):
25+
return "", 400
26+
27+
if not compare_digest(password,
28+
current_app.config["WORKER_PASSWORD"]):
29+
return "", 401
30+
31+
# send daily reminder emails only while challenge is active
32+
33+
if core.day_number() >= 1 and not core.challenge_ended():
34+
msg = Message("CHANGEME",
35+
sender=current_app.config["MAIL_DEFAULT_SENDER"],
36+
recipients=[current_app.config["MG_LIST"]])
37+
38+
msg.html = render_template("CHANGEME")
39+
40+
mail.send(msg)
41+
42+
return "", 200

CodeChallenge/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class DefaultConfig:
2929
MAIL_SUPPRESS_SEND = True
3030
MG_PRIVATE_KEY = os.getenv("MG_PRIVATE_KEY")
3131
MG_LIST = "codechallenge@school.codewizardshq.com"
32+
WORKER_PASSWORD = os.getenv("WORKER_PASSWORD")
3233

3334
# no trailing /
3435
EXTERNAL_URL = "https://challenge.codewizardshq.com"

Pipfile.lock

Lines changed: 9 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)