flask -> bottle, less bloat
parent
d2bffc0117
commit
fe97fbcbbf
59
srv.py
59
srv.py
|
@ -1,54 +1,26 @@
|
||||||
from flask import (Flask, request, redirect, render_template)
|
#!/usr/bin/env python
|
||||||
import flask
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from bottle import route, get, post, run, static_file, template, request
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from output import array
|
from output import array
|
||||||
|
|
||||||
app = Flask(__name__)
|
@get('/')
|
||||||
|
@get('/<first_id:int>/<second_id:int>/<third_id:int>')
|
||||||
def jsonify(data):
|
|
||||||
return flask.Markup(json.dumps(data))
|
|
||||||
|
|
||||||
app.jinja_env.filters['jsonify'] = jsonify
|
|
||||||
|
|
||||||
@app.route('/<int:first_id>/<int:second_id>/<int:third_id>')
|
|
||||||
@app.route('/')
|
|
||||||
def home(first_id=None, second_id=None, third_id=None):
|
def home(first_id=None, second_id=None, third_id=None):
|
||||||
return render_template('home.html')
|
return template("home")
|
||||||
|
|
||||||
@app.route('/api/words')
|
@get('/api/words')
|
||||||
def api_words():
|
def api_words():
|
||||||
# NOTE: below is old code from route('/') up for a review
|
|
||||||
#
|
|
||||||
#'''
|
|
||||||
# print len(array)
|
|
||||||
#while first_id == None:
|
|
||||||
# rand_int = randint(0, len(array)-1)
|
|
||||||
# value = array[rand_int]
|
|
||||||
# if len(value) > 0:
|
|
||||||
# first_id = rand_int
|
|
||||||
#while second_id == None:
|
|
||||||
# rand_int = randint(0, len(array)-1)
|
|
||||||
# value = array[rand_int]
|
|
||||||
# if len(value) > 0:
|
|
||||||
# second_id = rand_int
|
|
||||||
#'''
|
|
||||||
#
|
|
||||||
#def get_words(words):
|
|
||||||
# ret = []
|
|
||||||
# for word_id in words:
|
|
||||||
# word = array[word_id] if word_id != None and word_id < len(array) else random.choice(array)
|
|
||||||
# ret.append(word.decode('utf-8'))
|
|
||||||
# return ret
|
|
||||||
|
|
||||||
word1 = random.choice(array);
|
word1 = random.choice(array);
|
||||||
word2 = random.choice(array);
|
word2 = random.choice(array);
|
||||||
word3 = random.choice(array);
|
word3 = random.choice(array);
|
||||||
|
|
||||||
return json.dumps([word1, word2, word3])
|
return json.dumps([word1, word2, word3])
|
||||||
|
|
||||||
@app.route('/api/save', methods=['POST'])
|
@post('/api/save')
|
||||||
def api_save():
|
def api_save():
|
||||||
# TODO: This is a stub
|
# TODO: This is a stub
|
||||||
|
|
||||||
|
@ -57,7 +29,7 @@ def api_save():
|
||||||
err = None
|
err = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image_url = request.form['image_url']
|
image_url = request.forms.image_url
|
||||||
except KeyError:
|
except KeyError:
|
||||||
err = "No image_url provided"
|
err = "No image_url provided"
|
||||||
|
|
||||||
|
@ -68,9 +40,12 @@ def api_save():
|
||||||
print image_url
|
print image_url
|
||||||
return "Saved!"
|
return "Saved!"
|
||||||
|
|
||||||
@app.route('/manifest.webapp')
|
@get('/manifest.webapp')
|
||||||
def manifest():
|
def manifest():
|
||||||
return open('manifest.webapp').read()
|
return static_file('manifest.webapp', root='.')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
@get('/static/<path:path>')
|
||||||
app.run(host='127.0.0.1', port=6969, debug=True)
|
def serve_static(path):
|
||||||
|
return static_file(path, root='./static/')
|
||||||
|
|
||||||
|
run(host='localhost', port=6969, reloader=True)
|
||||||
|
|
|
@ -57,8 +57,8 @@
|
||||||
<span id="word2"></span>
|
<span id="word2"></span>
|
||||||
<br />
|
<br />
|
||||||
<div class="foot">Copyright © RiddleKiller Ltd.<br>Features Kelson Sans font by <a href=http://www.fontfabric.com/>FontFabric.com/</a></div>
|
<div class="foot">Copyright © RiddleKiller Ltd.<br>Features Kelson Sans font by <a href=http://www.fontfabric.com/>FontFabric.com/</a></div>
|
||||||
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-1.7.2.min.js') }}"></script>
|
<script type="text/javascript" src="/static/js/jquery-1.7.2.min.js"></script>
|
||||||
<script type="text/javascript" src="{{ url_for('static', filename='js/penis.js') }}"></script>
|
<script type="text/javascript" src="/static/js/penis.js"></script>
|
||||||
<!--<script type="text/javascript" src="{{ url_for('static', filename='js/home.js') }}"></script>-->
|
<!--<script type="text/javascript" src="/static/js/home.js"></script>-->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -48,8 +48,8 @@
|
||||||
</n2>
|
</n2>
|
||||||
</div>
|
</div>
|
||||||
<div class="foot">Copyright © RiddleKiller Ltd.</div>
|
<div class="foot">Copyright © RiddleKiller Ltd.</div>
|
||||||
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-1.7.2.min.js') }}"></script>
|
<script type="text/javascript" src="/static/js/jquery-1.7.2.min.js"></script>
|
||||||
<script type="text/javascript" src="{{ url_for('static', filename='js/penis.js') }}"></script>
|
<script type="text/javascript" src="/static/js/penis.js"></script>
|
||||||
<!--<script type="text/javascript" src="{{ url_for('static', filename='js/home.js') }}"></script>-->
|
<!--<script type="text/javascript" src="/static/js/home.js"></script>-->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue