from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route('/home', methods=['POST', 'GET'], defaults={'name' : 'Werner'})
@app.route('/home/<string:name>', methods=['POST', 'GET'])
def home(name):
    return '<h1>Hello {}, you are on the home page!</h1>'.format(name)

@app.route('/query')
def query():
    name = request.args.get('name')
    location = request.args.get('location')
    return '<h1>Hi {}. You are from {}. You are on the query page!</h1>'.format(name, location)

@app.route('/form', methods=['GET', 'POST'])
def form():
    if request.method == 'GET':
        return '''<form method="POST" action="/process">
                      <input type="text" name="name">Name <p>
                      <input type="text" name="location">Ort <p>
                      <input type="submit" value="Submit">
                  </form>'''
    else:
           name = request.form['name']
           location = request.form['location']
           return '<h1>Hello {}. You are from {} <h1>'.format(name, location)

@app.route('/process', methods=['POST'])
def process():
    name = request.form['name']
    location = request.form['location']
    return '<h1>Hello {}. You are from {} <h1>'.format(name, location)


@app.route('/json')
def json():
    return jsonify({"name":  "Franz", "hobby": ["Python","Java","C++"]})


@app.route('/processjson', methods=['POST','GET'])
def processjson():
    data = request.get_json()
    temp = data['temp']
    lum = data['lum']

    return jsonify({'result' : 'Success!', 'temp' : temp, 'lum' : lum})

#if __name__ == '__main__':
  #  app.run(debug=True)