world-ecoregion/biomes/web.py

27 lines
671 B
Python
Raw Normal View History

2019-04-22 07:57:20 +00:00
from flask import Flask, render_template, make_response, send_file, request
from map_generator import generate_map, parameters
app = Flask(__name__)
@app.route('/')
def index():
2019-04-22 07:57:20 +00:00
return render_template('index.html', parameters=parameters)
def parse(key, value):
t = parameters[key]['type']
if t == 'int':
return int(value)
elif t == 'float':
return float(value)
elif t == 'bool':
return value == 'on'
2019-04-22 07:57:20 +00:00
else:
return value
@app.route('/map')
def get_map():
2019-04-22 07:57:20 +00:00
params = { key: parse(key, request.args[key]) for key in request.args }
res = send_file(generate_map(**params), mimetype='image/png')
return res