SimpleSyndicate/ss.py
2019-10-21 10:31:28 -04:00

51 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""
The main Flask application for serving up aggregated RSS feed entries.
"""
import os
from flask import Flask, render_template, session, request
import config
import database
import buckler_flask
app = Flask(__name__)
app.session_interface = buckler_flask.BucklerSessionInterface()
app.before_request(buckler_flask.require_auth)
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():
"""
The index page.
"""
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"