2015-08-01 23:27:08 +00:00
|
|
|
from functools import lru_cache
|
2015-07-28 18:04:11 +00:00
|
|
|
import json
|
|
|
|
import os
|
2015-08-01 23:16:09 +00:00
|
|
|
import random
|
2015-07-28 18:04:11 +00:00
|
|
|
import time
|
|
|
|
from sys import argv
|
|
|
|
from tempfile import mkdtemp, mkstemp
|
2015-10-15 23:58:22 +00:00
|
|
|
import logging
|
2015-08-03 02:02:39 +00:00
|
|
|
|
|
|
|
from pyhocon import ConfigFactory
|
|
|
|
import requests
|
2015-07-28 18:04:11 +00:00
|
|
|
from flask import Flask, render_template, request, redirect
|
2015-08-03 02:02:39 +00:00
|
|
|
|
2015-10-05 20:20:22 +00:00
|
|
|
from tildetown.stats import get_data
|
2015-07-28 18:04:11 +00:00
|
|
|
|
2015-08-03 02:02:39 +00:00
|
|
|
## disgusting hack for python 3.4.0
|
2015-08-01 23:23:54 +00:00
|
|
|
import pkgutil
|
|
|
|
orig_get_loader = pkgutil.get_loader
|
|
|
|
def get_loader(name):
|
|
|
|
try:
|
|
|
|
return orig_get_loader(name)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
pkgutil.get_loader = get_loader
|
2015-08-03 02:02:39 +00:00
|
|
|
##########
|
2015-08-01 23:23:54 +00:00
|
|
|
|
2015-07-28 18:04:11 +00:00
|
|
|
SITE_NAME = 'tilde.town'
|
|
|
|
|
|
|
|
app = Flask('~cgi')
|
|
|
|
|
2016-09-05 10:56:27 +00:00
|
|
|
app.config['DEBUG'] = True
|
|
|
|
# tension between this and cfg function...
|
|
|
|
|
|
|
|
conf = ConfigFactory.parse_file('cfg.conf')
|
|
|
|
|
|
|
|
logging.basicConfig(filename='/tmp/cgi.log', level=logging.DEBUG)
|
|
|
|
|
2015-08-01 23:27:08 +00:00
|
|
|
@lru_cache(maxsize=32)
|
2015-08-01 23:16:09 +00:00
|
|
|
def site_context():
|
2015-08-01 23:27:08 +00:00
|
|
|
return get_data()
|
2015-08-01 23:16:09 +00:00
|
|
|
|
2015-07-28 18:04:11 +00:00
|
|
|
@app.route('/random', methods=['GET'])
|
|
|
|
def get_random():
|
2015-08-01 23:16:09 +00:00
|
|
|
user = random.choice(site_context()['live_users'])
|
|
|
|
return redirect('http://tilde.town/~{}'.format(user['username']))
|
2015-07-28 18:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run()
|