Created
June 11, 2012 05:53
-
-
Save barneygale/2908676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nerdnu import app | |
from flask import Flask, request, redirect, url_for, render_template, flash | |
import json | |
def load_json(fname): | |
f = open('nerdnu/data/%s' % fname, 'r') | |
o = json.load(f) | |
f.close() | |
return o | |
def load_html(fname): | |
f = open('nerdnu/data/%s' % fname, 'r') | |
o = f.read() | |
f.close() | |
return o | |
@app.route('/') | |
def index(): | |
return render_template('layout.html', title='Home', body='To be completed.', statuses=load_json('statuses.json')) | |
@app.route('/creative') | |
@app.route('/survival') | |
@app.route('/pve') | |
def server(): | |
name = request.path[1:] | |
statuses = load_json('statuses.json') | |
options = { | |
'title': name, | |
'statuses': statuses, | |
'addr': {'creative': 'c.nerd.nu', 'survival': 's.nerd.nu', 'pve': 'p.nerd.nu'}[name], | |
'description': load_html('info-%s.html' % name), | |
'status': statuses[name], | |
'subreddit': load_json('subreddit.json')[name], | |
'forum': load_json('forum.json')[name], | |
'current_rev': load_json('current_rev.json')[name], | |
'top_players': load_json('top_players.json')[name]} | |
return render_template('server.html', **options) | |
@app.route('/appeal') | |
def appeal(): | |
#TODO: post stuff. | |
return render_template('appeal.html', title='Appeal a ban', statuses=load_json('statuses.json')) | |
@app.route('/staff') | |
def staff(): | |
options = { | |
'title': 'Staff', | |
'statuses': load_json('statuses.json')} | |
for fname in glob.glob('/home/reddit/permissions/users/*.txt'): | |
with open(fname) as handle: | |
options[os.path.basename(fname)[:-4]] = map(lambda a: a.trim(), handle.readlines()) | |
return render_template('staff.html', **options) | |
@app.route('/rules') | |
def rules(): | |
options = { | |
'title': 'Rules', | |
'body': load_html('rules.html'), | |
'statuses': load_json('statuses.json')} | |
return render_template('wikipage.html', **options) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment