This commit is contained in:
ebby 2026-09-27 10:10:24 +02:00
parent 5d0d68c1f9
commit 97f0697502
21 changed files with 181 additions and 4 deletions

View file

@ -0,0 +1,63 @@
<!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 href="https://blauwasser-mausis.de/blog/bootsuche-england">
<span>Abbestellen</span>
</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-radius: 3px;
}
h3,
h4 {
margin: 0;
}
button {
padding: 12px;
background-color: azure;
border-radius: 3px;
border: none;
}
#admin {
margin-top: 64px;
color: red;
}
</style>

View file

@ -0,0 +1,61 @@
<!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-radius: 3px;
}
h3,
h4 {
margin: 0;
}
button {
padding: 12px;
background-color: azure;
border-radius: 3px;
border: none;
}
#admin {
margin-top: 64px;
color: red;
}
</style>

View 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

View file

@ -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 timedelta
from datetime import datetime from datetime import datetime
import feedparser 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(): def check_blog_rss_and_send_admin_mail():
feed = feedparser.parse(FEED_URL) feed = feedparser.parse(FEED_URL)
@ -11,11 +13,16 @@ def check_blog_rss_and_send_admin_mail():
date_string = str(article["published"]) date_string = str(article["published"])
date_object = datetime.strptime(date_string, '%a, %d %b %Y %H:%M:%S %Z') date_object = datetime.strptime(date_string, '%a, %d %b %Y %H:%M:%S %Z')
if date_object > (datetime.now() - timedelta(days=1)): if date_object > (datetime.now() - timedelta(days=15)):
print(f"Neu: {article["title"]}")
title = str(article["title"]) title = str(article["title"])
description = str(article["summary"]) 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 link
# TODO: create Template with jinja2 # TODO: create Template with jinja2
# TODO: send mail to blauwasser-mausis@proton.me # TODO: send mail to blauwasser-mausis@proton.me

View file

@ -28,3 +28,6 @@ router = APIRouter()
app.include_router(users.router) app.include_router(users.router)
app.include_router(comments.router) app.include_router(comments.router)
check_blog_rss_and_send_admin_mail()

View file

@ -19,7 +19,7 @@ export async function GET(context) {
customData: ` customData: `
<subtitle> <subtitle>
<![CDATA[${post.frontmatter.subtitle ?? ''}]]> <![CDATA[${post.frontmatter.subtitle}]]>
</subtitle> </subtitle>
`, `,