SimpleSyndicate/ss.py

51 lines
1.2 KiB
Python
Raw Normal View History

2018-10-21 01:03:14 -04:00
#!/usr/bin/env python3
"""
The main Flask application for serving up aggregated RSS feed entries.
"""
2019-01-21 08:19:54 -05:00
import os
from flask import Flask, render_template, session, request
2018-10-21 01:03:14 -04:00
import config
import database
2019-10-21 10:31:28 -04:00
import buckler_flask
2018-10-21 01:03:14 -04:00
app = Flask(__name__)
2019-10-21 10:31:28 -04:00
app.session_interface = buckler_flask.BucklerSessionInterface()
app.before_request(buckler_flask.require_auth)
2018-10-21 01:03:14 -04:00
2019-01-21 08:19:54 -05:00
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()
2018-10-21 01:03:14 -04:00
@app.route("/")
def index():
"""
The index page.
"""
feeds = []
for feed_url in config.FEEDS:
feeds.append(database.get_feed(feed_url))
2019-01-21 08:19:54 -05:00
style_sheet = session.get("style_sheet", "ss.css")
2018-10-21 01:03:14 -04:00
return render_template("index.html", **locals())
2019-01-21 08:19:54 -05:00
@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"