Browse Source

adding flask_apscheduler to update the Multifeeder every 10 minutes

master
manetta 3 years ago
parent
commit
afa1d8c6d1
  1. 1
      feedtools.py
  2. 1
      requirements.txt
  3. 14
      start.py
  4. 4
      templates/index.html

1
feedtools.py

@ -39,7 +39,6 @@ def update():
tmp['all_posts_sorted'][str(post_date)].append(post) tmp['all_posts_sorted'][str(post_date)].append(post)
db.update(tmp) db.update(tmp)
return db
def load(): def load():
db = SimpleDatabase('feeds.json', 'feeds.log') db = SimpleDatabase('feeds.json', 'feeds.log')

1
requirements.txt

@ -1,3 +1,4 @@
flask flask
feedparser feedparser
pathlib pathlib
Flask-APScheduler

14
start.py

@ -1,4 +1,5 @@
import flask import flask
import flask_apscheduler
import feedtools import feedtools
import json import json
@ -7,6 +8,19 @@ APP = flask.Flask(__name__,
static_folder="static", static_folder="static",
template_folder="templates") template_folder="templates")
# Initialize Flask-APScheduler
# https://github.com/viniciuschiele/flask-apscheduler
# Thanks Crunk for pointing to this extention!
scheduler = flask_apscheduler.APScheduler()
scheduler.api_enabled = False
scheduler.init_app(APP)
scheduler.start()
@scheduler.task('interval', id='update', minutes=10)
def update():
print('Updating the Multifeeder!')
feedtools.update()
@APP.route("/") @APP.route("/")
def index(): def index():
db = feedtools.load() db = feedtools.load()

4
templates/index.html

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>multifeeder</title> <title>-mu-l-t-i-f-e-e-d-e-r-</title>
<link rel="stylesheet" type="text/css" href="/css/stylesheet.css"> <link rel="stylesheet" type="text/css" href="/css/stylesheet.css">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
</head> </head>
@ -41,7 +41,7 @@
</section> </section>
<section id="feeds"> <section id="feeds">
<h1>Currently feeding</h1> <h1>Currently feeding</h1>
<p>The following feeds are rendered in the Multifeeder. The feeds in this list include streams of projects and activities in and around Varia.</p> <p>The following feeds are rendered in the Multifeeder. The feeds in this list include streams of projects and activities in and around Varia. The API is updated every 10 minutes.</p>
{% for x, feed in db['feeds'].items() %} {% for x, feed in db['feeds'].items() %}
<div class="feed el{{ x }}"> <div class="feed el{{ x }}">
<div class="title">{{ feed.title }}</div> <div class="title">{{ feed.title }}</div>

Loading…
Cancel
Save