remove old flask stuff
parent
9826a0da06
commit
1b7f68c631
|
@ -1,49 +0,0 @@
|
|||
from functools import lru_cache
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
from sys import argv
|
||||
from tempfile import mkdtemp, mkstemp
|
||||
import logging
|
||||
|
||||
from pyhocon import ConfigFactory
|
||||
import requests
|
||||
from flask import Flask, render_template, request, redirect
|
||||
|
||||
from tildetown.stats import get_data
|
||||
|
||||
## disgusting hack for python 3.4.0
|
||||
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
|
||||
##########
|
||||
|
||||
SITE_NAME = 'tilde.town'
|
||||
|
||||
app = Flask('~cgi')
|
||||
|
||||
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)
|
||||
|
||||
@lru_cache(maxsize=32)
|
||||
def site_context():
|
||||
return get_data()
|
||||
|
||||
@app.route('/random', methods=['GET'])
|
||||
def get_random():
|
||||
user = random.choice(site_context()['live_users'])
|
||||
return redirect('http://tilde.town/~{}'.format(user['username']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
|
@ -3,7 +3,17 @@ from sys import argv,stdin
|
|||
|
||||
from pystache import render
|
||||
|
||||
from tildetown.util import slurp
|
||||
def slurp(file_path):
|
||||
contents = None
|
||||
try:
|
||||
with open(file_path, 'r', encoding="utf-8") as f:
|
||||
contents = f.read()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
return contents
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
template = slurp(argv[1])
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{{site_name}} guestbook</title>
|
||||
<link rel="stylesheet" type="text/css" href="https://tilde.town/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{site_name}} guestbook</h1>
|
||||
<marquee behavior="alternate"><em style="font-size:150%">~*~*~*~*~*~*~*~*~*~*~*say hello*~*~*~*~*~*~*~*~*~*~*~</em></marquee>
|
||||
<form method="post">
|
||||
<table border="1px">
|
||||
<tr>
|
||||
<th>name!</th>
|
||||
<th>message!</th>
|
||||
<th>are you a robot!?</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" name="name" maxlength="140" />
|
||||
</td>
|
||||
<td>
|
||||
<textarea maxlength="400" style="border:0px"name="message" cols="50" rows="10"></textarea>
|
||||
</td>
|
||||
<td>
|
||||
<input type="radio" name="hmm" value="scriz" checked="true">yeah<br>
|
||||
<input type="radio" name="hmm" value="scrop">nope<br>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input style="font-size:200%" type="submit" value="sign"/>
|
||||
</form>
|
||||
|
||||
{% for post in posts %}
|
||||
<p>
|
||||
{{post.name}} says: {{post.message}}
|
||||
</p>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
|
@ -1,68 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> {{ site_name }} help desk </title>
|
||||
<link rel="stylesheet" href="https://tilde.town/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ site_name }} help desk</h1>
|
||||
<p>
|
||||
hi! this form exists to make it a little easier for {{ site_name }} admins
|
||||
to help people out with system issues like logging in, installing
|
||||
packages, and general questions about how to do stuff.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
in using this system, recall that there are only a handful of admins and
|
||||
you'll get a response (by email) as they are able to help out.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
thanks!
|
||||
</p>
|
||||
|
||||
{% if status == 'fail' %}
|
||||
<p style="background-color:red">
|
||||
oops, sorry! that didn't work. either something is wrong on the server or
|
||||
there was a problem with the form..try again?
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if status == 'success' %}
|
||||
<p style="background-color:green">
|
||||
hooray, your request has been sent.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<form method="post">
|
||||
<p>
|
||||
name: <input type="text" name="name" maxlength="140">
|
||||
</p>
|
||||
<p>
|
||||
email: <input type="email" name="email" maxlength="140" required="true">
|
||||
</p>
|
||||
<p>
|
||||
type of issue:
|
||||
<select name="type">
|
||||
<option value="login">help logging in</option>
|
||||
<option value="concern">concern about the site or another user</option>
|
||||
<option value="package">new package installed</option>
|
||||
<option value="question">a question</option>
|
||||
<option value="other">something else</option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
describe your issue (in 500 characters or less):<br>
|
||||
<textarea name="desc" required="true" rows="10" cols="50" maxlength="500">{{desc}}</textarea>
|
||||
</p>
|
||||
<p>
|
||||
are you a robot?<br>
|
||||
<input type="radio" name="hmm" value="scriz" checked="true">yeah<br>
|
||||
<input type="radio" name="hmm" value="scrop">nope<br>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="<3">
|
||||
</p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -1,20 +0,0 @@
|
|||
def slurp(file_path):
|
||||
contents = None
|
||||
try:
|
||||
with open(file_path, 'r', encoding="utf-8") as f:
|
||||
contents = f.read()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
return contents
|
||||
|
||||
def thread(initial, *fns):
|
||||
value = initial
|
||||
for fn in fns:
|
||||
value = fn(value)
|
||||
return value
|
||||
|
||||
def p(x):
|
||||
print(x)
|
||||
return x
|
Reference in New Issue