first pass at random
parent
0d32910dc7
commit
dc4aec8b95
|
@ -1,14 +1,22 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import time
|
import time
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from tempfile import mkdtemp, mkstemp
|
from tempfile import mkdtemp, mkstemp
|
||||||
from flask import Flask, render_template, request, redirect
|
from flask import Flask, render_template, request, redirect
|
||||||
|
from stats import get_data
|
||||||
|
|
||||||
SITE_NAME = 'tilde.town'
|
SITE_NAME = 'tilde.town'
|
||||||
|
|
||||||
app = Flask('~cgi')
|
app = Flask('~cgi')
|
||||||
|
|
||||||
|
_site_context = None
|
||||||
|
def site_context():
|
||||||
|
if not _site_context:
|
||||||
|
_site_context = get_data()
|
||||||
|
return _site_context
|
||||||
|
|
||||||
def slurp(file_path):
|
def slurp(file_path):
|
||||||
contents = None
|
contents = None
|
||||||
with open(file_path, 'r') as f:
|
with open(file_path, 'r') as f:
|
||||||
|
@ -28,7 +36,8 @@ def save_post(name, message):
|
||||||
|
|
||||||
@app.route('/random', methods=['GET'])
|
@app.route('/random', methods=['GET'])
|
||||||
def get_random():
|
def get_random():
|
||||||
return "RANDOM"
|
user = random.choice(site_context()['live_users'])
|
||||||
|
return redirect('http://tilde.town/~{}'.format(user['username']))
|
||||||
|
|
||||||
@app.route('/guestbook', methods=['GET'])
|
@app.route('/guestbook', methods=['GET'])
|
||||||
def get_guestbook():
|
def get_guestbook():
|
||||||
|
@ -37,9 +46,9 @@ def get_guestbook():
|
||||||
posts = map(lambda p: json.loads(slurp(os.path.join(data_dir, p))), os.listdir(data_dir))
|
posts = map(lambda p: json.loads(slurp(os.path.join(data_dir, p))), os.listdir(data_dir))
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"site_name": SITE_NAME,
|
|
||||||
"posts": posts,
|
"posts": posts,
|
||||||
}
|
}
|
||||||
|
context.update(site_context())
|
||||||
return render_template('guestbook.html', **context)
|
return render_template('guestbook.html', **context)
|
||||||
|
|
||||||
@app.route('/guestbook', methods=['POST'])
|
@app.route('/guestbook', methods=['POST'])
|
||||||
|
@ -49,7 +58,7 @@ def post_guestbook():
|
||||||
|
|
||||||
@app.route('/helpdesk', methods=['GET'])
|
@app.route('/helpdesk', methods=['GET'])
|
||||||
def helpdesk():
|
def helpdesk():
|
||||||
return "HELPDESK"
|
return "HELPDESK UNDER CONSTRUCTION"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(argv) == 2:
|
if len(argv) == 2:
|
||||||
|
|
Reference in New Issue