From 1a40bd2ee8e2bcba8c65aa9124eac7cc37bdb9ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 25 Mar 2018 15:13:05 +0200 Subject: [PATCH] Readme --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 9a99e97..8576c59 100644 --- a/README.md +++ b/README.md @@ -664,6 +664,7 @@ Web --- ```python import bottle +import urllib ``` ### Run @@ -673,10 +674,38 @@ bottle.run(host='0.0.0.0', port=80, server='cherypy') ``` ### Static request +```python +@route('/img/') +def send_image(image): + return static_file(image, 'images/', mimetype='image/png') +``` ### Dynamic request +```python +@route('/') +def send_page(sport): + sport = urllib.parse.unquote(sport).lower() + page = read_file(sport) + return template(page) +``` ### REST request +```python +@post('/p/') +def p_handler(sport): + team_1 = request.forms.get('team_1') + team_2 = request.forms.get('team_2') + team_1 = urllib.parse.unquote(team_1).lower() + team_2 = urllib.parse.unquote(team_2).lower() + + db = sqlite3.connect(conf.DB_PATH) + p_h, p_a = get_p(db, sport, team_1, team_2) + db.close() + + response.headers['Content-Type'] = 'application/json' + response.headers['Cache-Control'] = 'no-cache' + return json.dumps([p_h, p_a]) +``` Curses