diff --git a/README.md b/README.md index ae33b85..455829c 100644 --- a/README.md +++ b/README.md @@ -1049,60 +1049,6 @@ with open(, newline='') as csv_file: print(tabulate(reader, headers)) ``` -UrlLib ------- -### Translate special characters -```python -import urllib.parse - = urllib.parse.quote_plus() -``` - -Web ---- -```python -# $ pip3 install bottle -import bottle -import urllib -``` - -### Run -```python -bottle.run(host='localhost', port=8080) -bottle.run(host='0.0.0.0', port=80, server='cherrypy') -``` - -### 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 = bottle.request.forms.get('team') - team = urllib.parse.unquote(team).lower() - - db = sqlite3.connect() - home_odds, away_odds = get_p(db, sport, team) - db.close() - - response.headers['Content-Type'] = 'application/json' - response.headers['Cache-Control'] = 'no-cache' - return json.dumps([home_odds, away_odds]) -``` - Curses ------ ```python @@ -1157,6 +1103,60 @@ wf.writeframes(b''.join(frames)) wf.close() ``` +UrlLib +------ +### Translate special characters +```python +import urllib.parse + = urllib.parse.quote_plus() +``` + +Web +--- +```python +# $ pip3 install bottle +import bottle +import urllib +``` + +### Run +```python +bottle.run(host='localhost', port=8080) +bottle.run(host='0.0.0.0', port=80, server='cherrypy') +``` + +### 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 = bottle.request.forms.get('team') + team = urllib.parse.unquote(team).lower() + + db = sqlite3.connect() + home_odds, away_odds = get_p(db, sport, team) + db.close() + + response.headers['Content-Type'] = 'application/json' + response.headers['Cache-Control'] = 'no-cache' + return json.dumps([home_odds, away_odds]) +``` + Profile ------- #### Basic: