feed entries using feedgenerator

This commit is contained in:
crunk 2023-10-03 21:34:24 +02:00
parent eb39575627
commit 8dc1fdef15
2 changed files with 29 additions and 20 deletions

20
app.py
View File

@ -1,5 +1,3 @@
import flask_apscheduler
from feedgen.feed import FeedGenerator
from flask import Flask from flask import Flask
from flask_migrate import Migrate from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
@ -12,23 +10,7 @@ def create_app():
APP = Flask(__name__) APP = Flask(__name__)
APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///schedule.db" APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///schedule.db"
APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(APP) db.init_app(APP)
migrate.init_app(APP, db, render_as_batch=True) migrate.init_app(APP, db, render_as_batch=True)
create_rss_feed()
return APP return APP
def create_rss_feed():
print("creating rss feed")
fg = FeedGenerator()
fg.id("http://crunk.website")
fg.title("Crunk website")
fg.link(href="http://crunk.website", rel="alternate")
fg.subtitle("Some things crunk is doing!")
fg.link(href="http://crunk.website/test.atom", rel="self")
fg.language("en")
atomfeed = fg.atom_str(pretty=True)
rssfeed = fg.rss_str(pretty=True)
fg.atom_file("static/atom.xml")
fg.rss_file("static/rss.xml")

View File

@ -1,7 +1,34 @@
from feedgen.feed import FeedGenerator
from models.postmodel import Post from models.postmodel import Post
def update_rss_feed(): def update_rss_feed():
fg = create_rss_feed()
posts = Post.query.all() posts = Post.query.all()
for post in posts: for post in posts:
print(post.content) fe = fg.add_entry()
fe.id("http://lernfunk.de/media/654321/1")
fe.title(f"Crunk website:{post.id}")
fe.content(post.content)
fe.link(href="http://crunk.website")
write_rss_feed(fg)
def create_rss_feed():
print("creating rss feed")
fg = FeedGenerator()
fg.id("http://crunk.website")
fg.title("Crunk website")
fg.link(href="http://crunk.website", rel="alternate")
fg.subtitle("Some things crunk is doing!")
fg.link(href="http://crunk.website/test.atom", rel="self")
fg.language("en")
return fg
def write_rss_feed(fg):
atomfeed = fg.atom_str(pretty=True)
rssfeed = fg.rss_str(pretty=True)
fg.atom_file("static/atom.xml")
fg.rss_file("static/rss.xml")