A full featured blog in RiotJS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.4 KiB

#! /usr/bin/python3
8 years ago
from functools import partial
8 years ago
from flask import abort, Flask, render_template, flash, request, send_from_directory
8 years ago
from flask_appconfig import AppConfig
from urllib.parse import unquote
from urllib.parse import quote, unquote
8 years ago
from json import dumps, loads
8 years ago
from comment import testcomments
8 years ago
from werkzeug.contrib.cache import MemcachedCache
cache = MemcachedCache(['127.0.0.1:11211'])
import os
def cacheit(key, thunk):
"""
Tries to find a cached version of ``key''
If there is no cached version then it will
evaluate thunk (which must be a generator)
and cache that, then return the result
"""
cached = cache.get(quote(key))
if cached is None:
result = list(thunk())
cache.set(quote(key), result)
return result
return cached
def NeverWhere(configfile=None):
8 years ago
app = Flask(__name__)
app.config["TEMPLATES_AUTO_RELOAD"] = True
8 years ago
#def favicon():
#return send_from_directory("/srv/http/goal/favicon.ico",
#'favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route("/blog/", methods=("GET", "POST"))
8 years ago
def index():
print("matched index")
8 years ago
return render_template("index.html")
@app.route("/blog/scripts/<filename>", methods=("GET", "POST"))
8 years ago
def send_script(filename):
print("matched scripts route")
return send_from_directory("/srv/http/riotblog/scripts", filename)
8 years ago
@app.route("/blog/styles/<filename>", methods=("GET", "POST"))
8 years ago
def send_style(filename):
return send_from_directory("/srv/http/riotblog/styles", filename)
8 years ago
@app.route("/blog/switchpost/<pid>")
8 years ago
def switchPost(pid):
posts = {
"1" : "Post one is now changed as before! ",
"2" : "Post two here and it's changed again and again! "
8 years ago
}
8 years ago
return posts.get(pid, "false")
8 years ago
@app.route("/blog/comments/<pid>")
8 years ago
def comments(pid):
try:
return testcomments.get(int(pid), dumps([]))
except ValueError as e:
print(e)
8 years ago
return dumps([])
8 years ago
@app.route("/blog/insert/<pid>")
def insert(pid):
print("inserting new post")
8 years ago
@app.route("/<path:path>")
def page_not_found(path):
return "Custom failure message"
8 years ago
return app
app = NeverWhere()
if __name__ == "__main__":
NeverWhere("./appconfig").run(host="localhost", port=8001, debug=True)