-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
34 lines (26 loc) · 1008 Bytes
/
app.py
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
import os, random
from flask import (Flask, url_for, render_template, jsonify)
from settings import (IMAGES_FOLDER, IMAGES_URL, API_BASE)
### Init
app = Flask(__name__)
### Helpers
def get_image(waifu_name):
return '{}/{}/{}'.format(IMAGES_URL, waifu_name, random.choice(os.listdir('{}/{}'.format(IMAGES_FOLDER, waifu_name))))
### Routes
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/lily')
def lily():
image_url = get_image('lily')
title = 'Cute Cute Cute'
return render_template('picture.html', title = title, response = url_for('lily'), url = image_url)
@app.route('/sad')
def sad():
image_url = get_image('sad')
title = 'So It Goes'
return render_template('picture.html', title = title, response = url_for('sad'), url = image_url)
@app.route(API_BASE + '/waifu/<waifu_name>')
def get_random_image(waifu_name):
image_url = get_image(waifu_name)
return jsonify({'url': image_url, 'waifu': waifu_name})