helye/srv.py

52 lines
1.1 KiB
Python
Raw Normal View History

2013-04-16 18:11:57 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bottle import route, get, post, run, static_file, template, request
2013-01-26 16:52:21 +00:00
import json
import random
from output import array
2013-04-16 18:11:57 +00:00
@get('/')
@get('/<first_id:int>/<second_id:int>/<third_id:int>')
2013-01-26 16:52:21 +00:00
def home(first_id=None, second_id=None, third_id=None):
2013-04-16 18:11:57 +00:00
return template("home")
2013-01-26 16:52:21 +00:00
2013-04-16 18:11:57 +00:00
@get('/api/words')
def api_words():
2013-03-22 21:01:12 +00:00
word1 = random.choice(array);
word2 = random.choice(array);
word3 = random.choice(array);
return json.dumps([word1, word2, word3])
2013-04-16 18:11:57 +00:00
@post('/api/save')
def api_save():
# TODO: This is a stub
# also, is this necessary?
image_url = None
err = None
try:
2013-04-16 18:11:57 +00:00
image_url = request.forms.image_url
except KeyError:
err = "No image_url provided"
if err:
print err
return err
print image_url
return "Saved!"
2013-04-16 18:11:57 +00:00
@get('/manifest.webapp')
2013-01-26 16:52:21 +00:00
def manifest():
2013-04-16 18:11:57 +00:00
return static_file('manifest.webapp', root='.')
@get('/static/<path:path>')
def serve_static(path):
return static_file(path, root='./static/')
2013-01-26 16:52:21 +00:00
2013-04-16 18:11:57 +00:00
run(host='localhost', port=6969, reloader=True)