diff --git a/.gitignore b/.gitignore index 99e7728..3e6aeab 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__/ *.swo config.py *.txt +secret_key diff --git a/ss.py b/ss.py index 10582a6..caf996f 100644 --- a/ss.py +++ b/ss.py @@ -2,13 +2,26 @@ """ The main Flask application for serving up aggregated RSS feed entries. """ -from flask import Flask, render_template +import os + +from flask import Flask, render_template, session, request import config import database app = Flask(__name__) +def read_secret_key(): + if os.path.exists("secret_key"): + with open("secret_key", "rb") as file: + secret_key = file.read() + else: + secret_key = os.urandom(64) + with open("secret_key", "wb") as file: + file.write(secret_key) + app.secret_key = secret_key +read_secret_key() + @app.route("/") def index(): """ @@ -17,4 +30,18 @@ def index(): feeds = [] for feed_url in config.FEEDS: feeds.append(database.get_feed(feed_url)) + style_sheet = session.get("style_sheet", "ss.css") return render_template("index.html", **locals()) + + +@app.route("/set_session") +def set_session(): + """ + Allows certain values to be set in the client's session. + """ + style_sheet = request.args.get("style_sheet") + if style_sheet == "ss.css": + session["style_sheet"] = "ss.css" + elif style_sheet == "ss-dark.css": + session["style_sheet"] = "ss-dark.css" + return "true" diff --git a/static/ss-dark.css b/static/ss-dark.css new file mode 100644 index 0000000..3928ddb --- /dev/null +++ b/static/ss-dark.css @@ -0,0 +1,30 @@ +body { + background-color: #111111; + color: #FAFAFA; + font-family: Tahoma, Helvetica, sans-serif; + text-align: center; +} + +a:link { + text-decoration: none; + color: #004070; +} + +a:hover { + color: #B44444; +} + +a:visited { + color: #B44444; +} + +#globalContainer { + text-align: left; + display: inline-block; +} + +.date { + margin-left: 3em; + padding-right: 1em; + font-size: 0.9em; +} diff --git a/static/ss.js b/static/ss.js new file mode 100644 index 0000000..4f8ebb3 --- /dev/null +++ b/static/ss.js @@ -0,0 +1,14 @@ +function load() { + sheet = document.getElementById("styleSheet").href.replace(/^.*\//, ''); + select = document.getElementById("styleSheetSelector").value = sheet; +} + +function swapStyleSheet() { + var sheet = document.getElementById("styleSheetSelector").value; + document.getElementById("styleSheet").setAttribute("href", "/static/" + sheet); + + httpRequest = new XMLHttpRequest(); + httpRequest.onreadystatechange = function() {console.log(httpRequest.responseText);}; + httpRequest.open("GET", set_session_url + "?style_sheet=" + sheet, true); + httpRequest.send(); +} diff --git a/templates/index.html b/templates/index.html index be8fb02..7254ccc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,10 +2,21 @@ /ss/ - + + + +
+ Style sheet: + +
{% for feed in feeds %}