-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
200 lines (136 loc) · 4.3 KB
/
main.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from sanic import Sanic
from sanic.response import json, text
import os
from service.ChampionsLeagueService import ChampionsLeagueService
__author__ = "João Paulo Leite Nascimento"
__date__ = "31 January 2019"
__email__ = "joaopauloln7@gmail.com"
app = Sanic('Champions League Challenge')
# api path variable
PATH_API = '/api'
"""
" Route home
"""
@app.route("/", methods=['GET'])
async def home(request):
return text('API REST CHAMPIONS LEAGUE')
"""
" API home
"""
@app.route(PATH_API, methods=['GET'])
async def home(request):
return text('API REST CHAMPIONS LEAGUE')
"""
" 1. Route about
"""
@app.route(PATH_API + "/champions-league/", methods=['GET'])
async def about(request):
return json(ChampionsLeagueService.get_about())
"""
" 2. Route aboutFinal
"""
@app.route(PATH_API + "/champions-league/<season>", methods=['GET'])
async def about_final(request, season):
try:
ret = ChampionsLeagueService.get_about_by_season(season)
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 3. Route get all teams
"""
@app.route(PATH_API + "/champions-league/<season>/teams/", methods=['GET'])
async def teams(request, season):
try:
ret = ChampionsLeagueService.get_all_teams(season)
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 4. Route get one team
"""
@app.route(PATH_API + "/champions-league/<season>/teams/<name>", methods=['GET'])
async def team(request, season, name):
try:
ret = ChampionsLeagueService.get_one_team(season, name)
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 5. Route get all groups
"""
@app.route(PATH_API + "/champions-league/<season>/group-stage/", methods=['GET'])
async def groups(request, season):
try:
ret = ChampionsLeagueService.get_groups(season)
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 6. Route get one group variable name using only one letter between A and H
"""
@app.route(PATH_API + "/champions-league/<season>/group-stage/<name>", methods=['GET'])
async def group(request, season, name):
try:
ret = ChampionsLeagueService.get_groups(season, name)
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 7. Route round of 16
"""
@app.route(PATH_API + "/champions-league/<season>/round-of-16/", methods=['GET'])
async def round16(request, season):
try:
ret = ChampionsLeagueService.get_round_16(season)
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 8. Route round of 16 separated
"""
@app.route(PATH_API + "/champions-league/<season>/round-of-16/<team1>/vs/<team2>", methods=['GET'])
async def round_of_16_team_vs_team(request, season, team1, team2):
try:
ret = ChampionsLeagueService.get_playoffs(season, team1, team2, 'round-of-16')
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 9. Route quarter-finals
"""
@app.route(PATH_API + "/champions-league/<season>/quarter-finals/<team1>/vs/<team2>", methods=['GET'])
async def quarter_finals_team_vs_team(request, season, team1, team2):
try:
ret = ChampionsLeagueService.get_playoffs(season, team1, team2, 'quarter-finals')
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 10. Route semi-finals
"""
@app.route(PATH_API + "/champions-league/<season>/semi-finals/<team1>/vs/<team2>", methods=['GET'])
async def semi_finals_team_vs_team(request, season, team1, team2):
try:
ret = ChampionsLeagueService.get_playoffs(season, team1, team2, 'semi-finals')
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
"""
" 11 Route Final
"""
@app.route(PATH_API + "/champions-league/<season>/final/<team1>/vs/<team2>", methods=['GET'])
async def final(request, season, team1, team2):
try:
ret = ChampionsLeagueService.get_final(season, team1, team2)
except Exception as e:
ret = {"error ": str(e)}
return json(ret)
# Run App
if __name__ == "__main__":
#app.run(host="0.0.0.0", port=8000)
app.run(
host='0.0.0.0',
port=int(os.environ.get('PORT', 8000)),
workers=int(os.environ.get('WEB_CONCURRENCY', 1)),
debug=bool(os.environ.get('DEBUG', '')))