2022-08-25 15:10:08 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import sqlite3
|
|
|
|
from flask import Flask, request, render_template
|
|
|
|
from flask import g
|
|
|
|
from flask_paginate import Pagination, get_page_parameter
|
2022-08-27 12:48:40 +02:00
|
|
|
import confuse
|
2022-08-25 15:10:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
DATABASE = "../data/diffs.db"
|
2022-08-27 12:48:40 +02:00
|
|
|
CONFIG_FILE = "../data/config.yaml"
|
|
|
|
|
|
|
|
config = confuse.Configuration('headline', __name__)
|
|
|
|
config.set_file(CONFIG_FILE)
|
|
|
|
|
2022-08-25 15:10:08 +02:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_db():
|
2022-08-27 12:48:40 +02:00
|
|
|
db = getattr(g, '_database', None)
|
|
|
|
if db is None:
|
|
|
|
db = g._database = sqlite3.connect(DATABASE)
|
|
|
|
db.row_factory = sqlite3.Row
|
|
|
|
return db
|
2022-08-25 15:10:08 +02:00
|
|
|
|
|
|
|
@app.teardown_appcontext
|
|
|
|
def close_connection(exception):
|
2022-08-27 12:48:40 +02:00
|
|
|
db = getattr(g, '_database', None)
|
|
|
|
if db is not None:
|
|
|
|
db.close()
|
2022-08-25 15:10:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2022-08-27 12:48:40 +02:00
|
|
|
db = get_db().cursor()
|
|
|
|
db.execute('SELECT count(diff_id) FROM diffs')
|
|
|
|
diff_count = db.fetchall()[0][0]
|
|
|
|
|
|
|
|
|
|
|
|
#flask-paginate
|
|
|
|
page = request.args.get(get_page_parameter(), type=int, default=1)
|
|
|
|
|
|
|
|
pagination = Pagination(page=page, total=diff_count, record_name='diffs', css_framework='bootstrap5')
|
|
|
|
|
|
|
|
|
|
|
|
page_skip = pagination.skip
|
|
|
|
per_page = pagination.per_page
|
|
|
|
db.execute("SELECT * FROM diffs ORDER BY diff_id DESC LIMIT ? OFFSET ?", (per_page,page_skip))
|
|
|
|
diffs = db.fetchall()
|
|
|
|
|
|
|
|
return render_template('./index.html',
|
|
|
|
diffs=diffs,
|
|
|
|
pagination=pagination,
|
|
|
|
diff_count = diff_count
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/about')
|
|
|
|
def about():
|
|
|
|
return render_template('about.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/feeds')
|
|
|
|
def feed_list():
|
|
|
|
feeds = []
|
|
|
|
for conf in config['feeds']:
|
|
|
|
feed = {
|
|
|
|
'rss_source' : str(conf['rss_source']),
|
|
|
|
'unique_tag' : str(conf['unique_tag']),
|
|
|
|
'feed_name' : str(conf['name'])
|
|
|
|
}
|
|
|
|
feeds.append(feed)
|
|
|
|
return render_template('feeds.html', feeds=feeds)
|
2022-08-25 15:10:08 +02:00
|
|
|
if __name__ == "__main__":
|
2022-08-27 12:48:40 +02:00
|
|
|
app.run(host="0.0.0.0")
|