From 0157afbf52919f6467b5551add2e493d9b7715e0 Mon Sep 17 00:00:00 2001 From: mdivecky Date: Sat, 27 Aug 2022 12:48:40 +0200 Subject: [PATCH] Add about page and list of feeds, template parts --- view/app.py | 73 ++++++++++++------ view/requirements.txt | 3 +- view/static/favicon.ico | Bin 0 -> 15086 bytes view/static/main.css | 9 +++ view/templates/about.html | 26 +++++++ view/templates/feeds.html | 35 +++++++++ view/templates/index.html | 126 ++++++++++++++++--------------- view/templates/parts/footer.html | 6 ++ view/templates/parts/head.html | 6 ++ 9 files changed, 199 insertions(+), 85 deletions(-) create mode 100644 view/static/favicon.ico create mode 100644 view/static/main.css create mode 100644 view/templates/about.html create mode 100644 view/templates/feeds.html create mode 100644 view/templates/parts/footer.html create mode 100644 view/templates/parts/head.html diff --git a/view/app.py b/view/app.py index 3f3a342..c42bb3c 100644 --- a/view/app.py +++ b/view/app.py @@ -4,9 +4,15 @@ import sqlite3 from flask import Flask, request, render_template from flask import g from flask_paginate import Pagination, get_page_parameter +import confuse DATABASE = "../data/diffs.db" +CONFIG_FILE = "../data/config.yaml" + +config = confuse.Configuration('headline', __name__) +config.set_file(CONFIG_FILE) + app = Flask(__name__) @@ -14,43 +20,60 @@ app = Flask(__name__) def get_db(): - db = getattr(g, '_database', None) - if db is None: - db = g._database = sqlite3.connect(DATABASE) - db.row_factory = sqlite3.Row - return db + db = getattr(g, '_database', None) + if db is None: + db = g._database = sqlite3.connect(DATABASE) + db.row_factory = sqlite3.Row + return db @app.teardown_appcontext def close_connection(exception): - db = getattr(g, '_database', None) - if db is not None: - db.close() + db = getattr(g, '_database', None) + if db is not None: + db.close() @app.route('/') def index(): - db = get_db().cursor() - db.execute('SELECT count(diff_id) FROM diffs') - diff_count = db.fetchall()[0][0] + 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) + #flask-paginate + page = request.args.get(get_page_parameter(), type=int, default=1) - pagination = Pagination(page=page, total=diff_count, record_name='diffs') - - - 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() + 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, - ) + 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) if __name__ == "__main__": - app.run(host="0.0.0.0") \ No newline at end of file + app.run(host="0.0.0.0") \ No newline at end of file diff --git a/view/requirements.txt b/view/requirements.txt index 247b64a..05f5821 100644 --- a/view/requirements.txt +++ b/view/requirements.txt @@ -1,2 +1,3 @@ flask -flask-paginate \ No newline at end of file +flask-paginate +confuse \ No newline at end of file diff --git a/view/static/favicon.ico b/view/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..1974a56b6fbc9500bdc4c5a3262579aa4a5a4ecb GIT binary patch literal 15086 zcmeHOJ8l#~5N&G_Bt}>e0@4N`6FMS5AP7NRf{*|Xz$aJ>2?63DK*9wG9Pkm5Z-5ZS zkRW6rMGWulY^}@9)J*OCJQm$jQPtJ2s$SRh&e+2`grzVFYij{|9G;yG;d}^TJf6*0 zLihmR3N+Vm9tz%?OD*c-}&_M?dBj+v1JIF6cHZUQlw-9n9S3OQ* zvI!X)XNwQHk~7B<$U)*Rdm?9EhuaYG9W>3e^!@Gve&eJ4T=do$**1 zbso$1^xujdfHlL62v(K|HUB|+Ep1nFxUAyde zK#QBM<-urt7q-R0@@ozrjK+6iTO2IE=HS6-d>6LG!SZVk9*o9!VOtz5zvke-++r*8<)FLHPS ziLZl)zxQ`2ooi8>{Nmr;bU!`$G=6Ay;$Qsv>FYXq`X7Hb`r=kq=c|W2FxEY)Du37O zkDUDZ^EdY}lScw<@e_KhMMH?avy37NA}_8KGx^$NVtf;2;U{c4|n0v zc*a{pc_aQ=Ba+(fv);nmDlQj*}0aOD&6G%UzOXtUU&cA{8hMAfA?8k)C=ifye9sp zI?lU=gxV+hwU2gNBhGsri9bWcFLh)ty6nC#F;!asoFsXz7+LRH54C=LF1qN$Cu{TY z$LFH$`rO~OlKTI}QvSXmf0Z$rzEQ}xy?l9dXDXQT3vqKX{TcAZ@)Z8x$RY9vb)+ue zQ}DIK7&3oPfxk8DVDMVkInz9&S8K+~nPm>K@mF + + + + {% include 'parts/head.html' %} + + + + + +
+
+

Headliner

+

Headliner is monitoring rss feeds of czech news websites for changes in article headlines. Just + because it might be interesting.

+

See the source code, but be aware that it's not too nice. + Feel free to improve it.

+

If you want to access the raw data collected by this tool, write us an e-mail, you can find the contact on our + website below.

+
+
+ + {% include 'parts/footer.html' %} + + + \ No newline at end of file diff --git a/view/templates/feeds.html b/view/templates/feeds.html new file mode 100644 index 0000000..8c15342 --- /dev/null +++ b/view/templates/feeds.html @@ -0,0 +1,35 @@ + + + + + {% include 'parts/head.html' %} + + + + +
+
+ + + + + + + + + + {% for feed in feeds %} + + + + + + {% endfor %} + +
NameRSS/Atom URLUnique tag
{{ feed.feed_name }}{{ feed.rss_source | urlize(target="_blank") }}{{ feed.unique_tag }}
+
+
+ {% include 'parts/footer.html' %} + + + \ No newline at end of file diff --git a/view/templates/index.html b/view/templates/index.html index 4bfb78f..eb9bec2 100644 --- a/view/templates/index.html +++ b/view/templates/index.html @@ -1,66 +1,74 @@ - - - - Headliner - - + + + + + +
+
+ + + + + + + + + + + + {% for diff in diffs %} + + + + + + + + {% endfor %} + +
Detection timeSourceDiffOriginalChanged
{{ diff.diff_time }}{{ diff.feed_name }}{{ diff.diff_html|safe }} + {{ diff.title_orig|truncate(15) }} + {{ diff.title_orig }} + + {{ diff.title_new|truncate(15) }} + {{ diff.title_new}} +
- +
+
+
+ {{ pagination.links }} +
+
+ {{ pagination.info }} +
+
+
+
+ {% include 'parts/footer.html' %} + + \ No newline at end of file diff --git a/view/templates/parts/footer.html b/view/templates/parts/footer.html new file mode 100644 index 0000000..b44d635 --- /dev/null +++ b/view/templates/parts/footer.html @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/view/templates/parts/head.html b/view/templates/parts/head.html new file mode 100644 index 0000000..65bcdf7 --- /dev/null +++ b/view/templates/parts/head.html @@ -0,0 +1,6 @@ + + +Headliner + + +