timezone and time added to post

This commit is contained in:
crunk 2023-10-08 23:44:00 +02:00
parent 8dc1fdef15
commit f1b606852b
5 changed files with 14 additions and 6 deletions

Binary file not shown.

View File

@ -9,8 +9,8 @@ class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String, nullable=False)
files = db.Column(db.String(300), nullable=True, unique=False)
last_updated = db.Column(db.DateTime)
scheduled_time = db.Column(db.DateTime)
last_updated = db.Column(db.DateTime(timezone=True))
scheduled_time = db.Column(db.DateTime(timezone=True))
def __repr__(self):
return "<Post %r>" % self.id

View File

@ -1,4 +1,5 @@
from datetime import datetime
from zoneinfo import ZoneInfo
from app import db
from models.postmodel import Post
@ -9,10 +10,13 @@ from sqlalchemy.exc import (DatabaseError, DataError, IntegrityError,
def schedule_text(request):
print(request.form["text"])
try:
text = request.form["text"]
content = f"<p>{text}</p>"
zoneinfo = ZoneInfo("Europe/Berlin")
post = Post(
content=request.form["text"],
last_updated=datetime.now(),
scheduled_time=datetime.now(),
content=content,
last_updated=datetime.now().astimezone(tz=zoneinfo),
scheduled_time=datetime.now().astimezone(tz=zoneinfo),
)
db.session.add(post)
db.session.commit()

View File

@ -1,5 +1,5 @@
import flask_apscheduler
from flask import Flask, request
from flask import Blueprint, Flask, request
from app import create_app
from scheduler.schedule_text import schedule_text

View File

@ -1,3 +1,5 @@
from zoneinfo import ZoneInfo
from feedgen.feed import FeedGenerator
from models.postmodel import Post
@ -5,12 +7,14 @@ from models.postmodel import Post
def update_rss_feed():
fg = create_rss_feed()
zoneinfo = ZoneInfo("Europe/Berlin")
posts = Post.query.all()
for post in posts:
fe = fg.add_entry()
fe.id("http://lernfunk.de/media/654321/1")
fe.title(f"Crunk website:{post.id}")
fe.content(post.content)
fe.published(post.scheduled_time.astimezone(tz=zoneinfo))
fe.link(href="http://crunk.website")
write_rss_feed(fg)