-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
66 lines (45 loc) · 1.35 KB
/
index.py
File metadata and controls
66 lines (45 loc) · 1.35 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
FormaServe IBM i Training
Main index file for the Cocktail training application.
To install follow the instructions in the readme file and make note of the licensing requirements.
For full disclaimer see https://www.formaserve.co.uk/examples.php
© - FormaServe Systems Ltd. 1990 - 2024
www.FormaServe.co.uk
powerwire.eu
'''
from bottle import route, debug, run, template, static_file, error, request
import requests
import json
@route('/static/<filename>')
def server_static(filename):
'''
create static file routes
'''
return static_file(filename, root='./static')
# home route
@route('/')
def home():
'''
home/index route
'''
if request.GET.search:
name = request.GET.search.strip()
url = f"https://www.thecocktaildb.com/api/json/v1/1/search.php?s={name}"
res = requests.get(url)
res = res.json()
drinks = res['drinks'][0]
return template('./views/cocktail-home', drinks=drinks)
else:
return template('./views/cocktail-search')
@route('/search')
def search():
return template('./views/cocktail-search')
@error(403)
def error403(code):
return 'There is a mistake in your URL!'
@error()
@error(404)
def error(error):
return template('cocktail-error')
# start the server http://0.0.0.0:3638
run(host='0.0.0.0', port=3638, debug=True, reloader=True)