feed entries from db

This commit is contained in:
crunk 2023-10-03 20:31:36 +02:00
parent 4cf0e2fac2
commit eb39575627
5 changed files with 22 additions and 17 deletions

15
app.py
View File

@ -10,22 +10,12 @@ migrate = Migrate()
def create_app(): def create_app():
APP = Flask(__name__) APP = Flask(__name__)
scheduler = flask_apscheduler.APScheduler()
scheduler.api_enabled = True
scheduler.init_app(APP)
scheduler.start()
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() create_rss_feed()
@scheduler.task("interval", id="update", minutes=10)
def update():
update_rss_feed()
return APP return APP
@ -34,7 +24,6 @@ def create_rss_feed():
fg = FeedGenerator() fg = FeedGenerator()
fg.id("http://crunk.website") fg.id("http://crunk.website")
fg.title("Crunk website") fg.title("Crunk website")
fg.author({"name": "John Doe", "email": "john@example.de"})
fg.link(href="http://crunk.website", rel="alternate") fg.link(href="http://crunk.website", rel="alternate")
fg.subtitle("Some things crunk is doing!") fg.subtitle("Some things crunk is doing!")
fg.link(href="http://crunk.website/test.atom", rel="self") fg.link(href="http://crunk.website/test.atom", rel="self")
@ -43,7 +32,3 @@ def create_rss_feed():
rssfeed = fg.rss_str(pretty=True) rssfeed = fg.rss_str(pretty=True)
fg.atom_file("static/atom.xml") fg.atom_file("static/atom.xml")
fg.rss_file("static/rss.xml") fg.rss_file("static/rss.xml")
def update_rss_feed():
print("updating rss feed")

View File

@ -1,10 +1,23 @@
import flask_apscheduler
from flask import Flask, request from flask import 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
from updater import update_rss_feed
APP = create_app() APP = create_app()
scheduler = flask_apscheduler.APScheduler()
scheduler.api_enabled = False
scheduler.init_app(APP)
scheduler.start()
@scheduler.task("interval", id="update", minutes=1)
def update():
with APP.app_context():
update_rss_feed()
@APP.route("/") @APP.route("/")
def index(): def index():

View File

@ -1,2 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><id>http://crunk.website</id><title>Crunk website</title><updated>2023-10-02T19:08:59.272412+00:00</updated><author><name>John Doe</name><email>john@example.de</email></author><link href="http://crunk.website" rel="alternate"/><link href="http://crunk.website/test.atom" rel="self"/><generator uri="https://lkiesow.github.io/python-feedgen" version="0.9.0">python-feedgen</generator><subtitle>Some things crunk is doing!</subtitle></feed> <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><id>http://crunk.website</id><title>Crunk website</title><updated>2023-10-03T18:20:53.506614+00:00</updated><link href="http://crunk.website" rel="alternate"/><link href="http://crunk.website/test.atom" rel="self"/><generator uri="https://lkiesow.github.io/python-feedgen" version="0.9.0">python-feedgen</generator><subtitle>Some things crunk is doing!</subtitle></feed>

View File

@ -1,2 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Crunk website</title><link>http://crunk.website/test.atom</link><description>Some things crunk is doing!</description><atom:link href="http://crunk.website/test.atom" rel="self"/><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><language>en</language><lastBuildDate>Mon, 02 Oct 2023 19:08:59 +0000</lastBuildDate></channel></rss> <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Crunk website</title><link>http://crunk.website/test.atom</link><description>Some things crunk is doing!</description><atom:link href="http://crunk.website/test.atom" rel="self"/><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><language>en</language><lastBuildDate>Tue, 03 Oct 2023 18:20:53 +0000</lastBuildDate></channel></rss>

7
updater.py Normal file
View File

@ -0,0 +1,7 @@
from models.postmodel import Post
def update_rss_feed():
posts = Post.query.all()
for post in posts:
print(post.content)