From f1b606852be45f35fb12b61e771f67b865a7f3cf Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 8 Oct 2023 23:44:00 +0200 Subject: [PATCH] timezone and time added to post --- instance/schedule.db-journal | Bin 4616 -> 0 bytes models/postmodel.py | 4 ++-- scheduler/schedule_text.py | 10 +++++++--- start.py | 2 +- updater.py | 4 ++++ 5 files changed, 14 insertions(+), 6 deletions(-) delete mode 100644 instance/schedule.db-journal diff --git a/instance/schedule.db-journal b/instance/schedule.db-journal deleted file mode 100644 index 4a39e6c59dd4aad52c0d782c155f84933fef88aa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4616 zcmeI$u?~VT5C-4_44bK&gA1Dzq`hJV7Q^Iom{`L=M1j$F)93LitkHx-!V8%HmTPmD zKj}A?XejUTyt>5q0e|jZ7YI$_E^e-&AOHafKmY;|fB*y_009U<00I#B z2<(H9)>M{l*F`65kI|*+dX}tXC1a@~R)y9D>%?TzFi%dlr61DD1s%>!U)grFs7xYF j$}Z$L{5w%<=Y_O%5tXg$X0#?{l4_IXo5@N3{`YwS@|`h0 diff --git a/models/postmodel.py b/models/postmodel.py index bdb672b..a5e5406 100644 --- a/models/postmodel.py +++ b/models/postmodel.py @@ -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 "" % self.id diff --git a/scheduler/schedule_text.py b/scheduler/schedule_text.py index 30ebc90..b78cc99 100644 --- a/scheduler/schedule_text.py +++ b/scheduler/schedule_text.py @@ -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"

{text}

" + 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() diff --git a/start.py b/start.py index 47e7e7a..0c074d1 100644 --- a/start.py +++ b/start.py @@ -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 diff --git a/updater.py b/updater.py index a7f96f0..1cbd122 100644 --- a/updater.py +++ b/updater.py @@ -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)