Browse Source

feed entries from db

main
crunk 1 year ago
parent
commit
eb39575627
  1. 15
      app.py
  2. 13
      start.py
  3. 2
      static/atom.xml
  4. 2
      static/rss.xml
  5. 7
      updater.py

15
app.py

@ -10,22 +10,12 @@ migrate = Migrate()
def create_app():
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_TRACK_MODIFICATIONS"] = False
db.init_app(APP)
migrate.init_app(APP, db, render_as_batch=True)
create_rss_feed()
@scheduler.task("interval", id="update", minutes=10)
def update():
update_rss_feed()
return APP
@ -34,7 +24,6 @@ def create_rss_feed():
fg = FeedGenerator()
fg.id("http://crunk.website")
fg.title("Crunk website")
fg.author({"name": "John Doe", "email": "john@example.de"})
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")
@ -43,7 +32,3 @@ def create_rss_feed():
rssfeed = fg.rss_str(pretty=True)
fg.atom_file("static/atom.xml")
fg.rss_file("static/rss.xml")
def update_rss_feed():
print("updating rss feed")

13
start.py

@ -1,10 +1,23 @@
import flask_apscheduler
from flask import Flask, request
from app import create_app
from scheduler.schedule_text import schedule_text
from updater import update_rss_feed
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("/")
def index():

2
static/atom.xml

@ -1,2 +1,2 @@
<?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>

2
static/rss.xml

@ -1,2 +1,2 @@
<?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

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