Browse Source

timezone and time added to post

main
crunk 1 year ago
parent
commit
f1b606852b
  1. BIN
      instance/schedule.db-journal
  2. 4
      models/postmodel.py
  3. 10
      scheduler/schedule_text.py
  4. 2
      start.py
  5. 4
      updater.py

BIN
instance/schedule.db-journal

Binary file not shown.

4
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 "<Post %r>" % self.id

10
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"<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()

2
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

4
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)

Loading…
Cancel
Save