1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bottle import route, get, post, run, static_file, template, request
import json
import random
from output import array
@get('/')
@get('/<first_id:int>/<second_id:int>/<third_id:int>')
def home(first_id=None, second_id=None, third_id=None):
return template("home")
@get('/api/words')
def api_words():
word1 = random.choice(array);
word2 = random.choice(array);
word3 = random.choice(array);
return json.dumps([word1, word2, word3])
@post('/api/save')
def api_save():
# TODO: This is a stub
# also, is this necessary?
image_url = None
err = None
try:
image_url = request.forms.image_url
except KeyError:
err = "No image_url provided"
if err:
print err
return err
print image_url
return "Saved!"
@get('/manifest.webapp')
def manifest():
return static_file('manifest.webapp', root='.')
@get('/static/<path:path>')
def serve_static(path):
return static_file(path, root='./static/')
run(host='localhost', port=6969, reloader=True)
|