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 0000000..1974a56 Binary files /dev/null and b/view/static/favicon.ico differ diff --git a/view/static/main.css b/view/static/main.css new file mode 100644 index 0000000..741424c --- /dev/null +++ b/view/static/main.css @@ -0,0 +1,9 @@ +body { + margin-bottom: 60px; /* Margin bottom by footer height */ + } + +.footer { + position: absolute; + bottom: 0; + width: 100%; + } \ No newline at end of file diff --git a/view/templates/about.html b/view/templates/about.html new file mode 100644 index 0000000..ce60a0d --- /dev/null +++ b/view/templates/about.html @@ -0,0 +1,26 @@ + + + + + {% 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 + + +