template
This commit is contained in:
parent
5d0d68c1f9
commit
8989a6f1b1
21 changed files with 173 additions and 4 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
58
backend/src/backend/internal/jinja_templates/approval.jinja
Normal file
58
backend/src/backend/internal/jinja_templates/approval.jinja
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Newsletter</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<h1>Neuer Artikel:</h1>
|
||||
<h3>{{data.title}}</h3>
|
||||
<h4>{{data.subtitle}}</h4>
|
||||
<p>{{data.description}}</p>
|
||||
|
||||
<a href={{data.link}}>
|
||||
<button>Zum Artikel</button>
|
||||
</a>
|
||||
|
||||
<a id="admin" href="https://blauwasser-mausis.de">Approve</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<style>
|
||||
* {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 32px;
|
||||
|
||||
}
|
||||
|
||||
div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
background-color: lightgrey;
|
||||
padding: 32px 64px;
|
||||
border: 3px;
|
||||
}
|
||||
|
||||
h3, h4 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 12px;
|
||||
background-color: blanchedalmond;
|
||||
border-radius: 3px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#admin {
|
||||
margin-top: 64px;
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
58
backend/src/backend/internal/jinja_templates/output.html
Normal file
58
backend/src/backend/internal/jinja_templates/output.html
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Newsletter</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<h1>Neuer Artikel:</h1>
|
||||
<h3>England</h3>
|
||||
<h4>It's gettin' british, my dear!</h4>
|
||||
<p>Auf geht's nach Milano! Aber Moment mal...der Artikel heißt England?! Da kann irgendwas nicht stimmen. Ich frage mal in der Redaktion nach. Ihr lest währenddessen einfach schonmal weiter.</p>
|
||||
|
||||
<a href=https://blauwasser-mausis.de/blog/bootsuche-england/>
|
||||
<button>Zum Artikel</button>
|
||||
</a>
|
||||
|
||||
<a id="admin" href="https://blauwasser-mausis.de">Approve</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<style>
|
||||
* {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 32px;
|
||||
|
||||
}
|
||||
|
||||
div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
background-color: lightgrey;
|
||||
padding: 32px 64px;
|
||||
border: 3px;
|
||||
}
|
||||
|
||||
h3, h4 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 12px;
|
||||
background-color: blanchedalmond;
|
||||
border-radius: 3px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#admin {
|
||||
margin-top: 64px;
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
43
backend/src/backend/internal/mail_util.py
Normal file
43
backend/src/backend/internal/mail_util.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from mailtrap import Mail
|
||||
import mailtrap as mt
|
||||
import os
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
|
||||
class Newsletter():
|
||||
def __init__(self, title, subtitle, description, link):
|
||||
self.title=title
|
||||
self.subtitle=subtitle
|
||||
self.description=description
|
||||
self.link=link
|
||||
|
||||
title: str
|
||||
subtitle: str
|
||||
description: str
|
||||
link: str
|
||||
|
||||
def send_newsletter_admin_approval(data: Newsletter ):
|
||||
env = Environment(loader = FileSystemLoader('src/backend/internal/jinja_templates'))
|
||||
template = env.get_template('approval.jinja')
|
||||
output = template.render(data=data)
|
||||
|
||||
|
||||
with open("src/backend/internal/jinja_templates/output.html", "w") as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
mail = mt.Mail(
|
||||
sender=mt.Address(email="newsletter@blauwasser-mausis.de", name="Flaschenpost"),
|
||||
to=[mt.Address(email="blauwasser-mausis@proton.me")],
|
||||
subject=f"[Approval] {data.title}",
|
||||
text="Jinja2 Template",
|
||||
)
|
||||
|
||||
|
||||
|
||||
def send_mail(mail: Mail):
|
||||
client = mt.MailtrapClient(token="<YOUR_API_TOKEN>")
|
||||
client.send(mail)
|
||||
|
||||
def send_batch_mail():
|
||||
pass
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
|
||||
from backend.internal.mail_util import Newsletter
|
||||
from backend.internal.mail_util import send_newsletter_admin_approval
|
||||
from datetime import timedelta
|
||||
from datetime import datetime
|
||||
import feedparser
|
||||
|
||||
FEED_URL="https://blauwasser-mausis.de/rss.xml"
|
||||
FEED_URL="http://localhost:4321/rss.xml"
|
||||
|
||||
def check_blog_rss_and_send_admin_mail():
|
||||
feed = feedparser.parse(FEED_URL)
|
||||
|
|
@ -11,11 +13,16 @@ def check_blog_rss_and_send_admin_mail():
|
|||
date_string = str(article["published"])
|
||||
date_object = datetime.strptime(date_string, '%a, %d %b %Y %H:%M:%S %Z')
|
||||
|
||||
if date_object > (datetime.now() - timedelta(days=1)):
|
||||
print(f"Neu: {article["title"]}")
|
||||
if date_object > (datetime.now() - timedelta(days=15)):
|
||||
title = str(article["title"])
|
||||
description = str(article["summary"])
|
||||
subtitle = str(article["subtitle"])
|
||||
link = str(article["link"])
|
||||
|
||||
data = Newsletter(title, subtitle, description, link)
|
||||
|
||||
send_newsletter_admin_approval(data)
|
||||
|
||||
# TODO: create link
|
||||
# TODO: create Template with jinja2
|
||||
# TODO: send mail to blauwasser-mausis@proton.me
|
||||
|
|
|
|||
|
|
@ -28,3 +28,6 @@ router = APIRouter()
|
|||
app.include_router(users.router)
|
||||
app.include_router(comments.router)
|
||||
|
||||
check_blog_rss_and_send_admin_mail()
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -19,7 +19,7 @@ export async function GET(context) {
|
|||
|
||||
customData: `
|
||||
<subtitle>
|
||||
<![CDATA[${post.frontmatter.subtitle ?? ''}]]>
|
||||
<![CDATA[${post.frontmatter.subtitle}]]>
|
||||
</subtitle>
|
||||
|
||||
`,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue