timezone and time added to post
This commit is contained in:
parent
8dc1fdef15
commit
f1b606852b
Binary file not shown.
@ -9,8 +9,8 @@ class Post(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
content = db.Column(db.String, nullable=False)
|
content = db.Column(db.String, nullable=False)
|
||||||
files = db.Column(db.String(300), nullable=True, unique=False)
|
files = db.Column(db.String(300), nullable=True, unique=False)
|
||||||
last_updated = db.Column(db.DateTime)
|
last_updated = db.Column(db.DateTime(timezone=True))
|
||||||
scheduled_time = db.Column(db.DateTime)
|
scheduled_time = db.Column(db.DateTime(timezone=True))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Post %r>" % self.id
|
return "<Post %r>" % self.id
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from models.postmodel import Post
|
from models.postmodel import Post
|
||||||
@ -9,10 +10,13 @@ from sqlalchemy.exc import (DatabaseError, DataError, IntegrityError,
|
|||||||
def schedule_text(request):
|
def schedule_text(request):
|
||||||
print(request.form["text"])
|
print(request.form["text"])
|
||||||
try:
|
try:
|
||||||
|
text = request.form["text"]
|
||||||
|
content = f"<p>{text}</p>"
|
||||||
|
zoneinfo = ZoneInfo("Europe/Berlin")
|
||||||
post = Post(
|
post = Post(
|
||||||
content=request.form["text"],
|
content=content,
|
||||||
last_updated=datetime.now(),
|
last_updated=datetime.now().astimezone(tz=zoneinfo),
|
||||||
scheduled_time=datetime.now(),
|
scheduled_time=datetime.now().astimezone(tz=zoneinfo),
|
||||||
)
|
)
|
||||||
db.session.add(post)
|
db.session.add(post)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
2
start.py
2
start.py
@ -1,5 +1,5 @@
|
|||||||
import flask_apscheduler
|
import flask_apscheduler
|
||||||
from flask import Flask, request
|
from flask import Blueprint, Flask, request
|
||||||
|
|
||||||
from app import create_app
|
from app import create_app
|
||||||
from scheduler.schedule_text import schedule_text
|
from scheduler.schedule_text import schedule_text
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from feedgen.feed import FeedGenerator
|
from feedgen.feed import FeedGenerator
|
||||||
|
|
||||||
from models.postmodel import Post
|
from models.postmodel import Post
|
||||||
@ -5,12 +7,14 @@ from models.postmodel import Post
|
|||||||
|
|
||||||
def update_rss_feed():
|
def update_rss_feed():
|
||||||
fg = create_rss_feed()
|
fg = create_rss_feed()
|
||||||
|
zoneinfo = ZoneInfo("Europe/Berlin")
|
||||||
posts = Post.query.all()
|
posts = Post.query.all()
|
||||||
for post in posts:
|
for post in posts:
|
||||||
fe = fg.add_entry()
|
fe = fg.add_entry()
|
||||||
fe.id("http://lernfunk.de/media/654321/1")
|
fe.id("http://lernfunk.de/media/654321/1")
|
||||||
fe.title(f"Crunk website:{post.id}")
|
fe.title(f"Crunk website:{post.id}")
|
||||||
fe.content(post.content)
|
fe.content(post.content)
|
||||||
|
fe.published(post.scheduled_time.astimezone(tz=zoneinfo))
|
||||||
fe.link(href="http://crunk.website")
|
fe.link(href="http://crunk.website")
|
||||||
write_rss_feed(fg)
|
write_rss_feed(fg)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user