-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
30 lines (22 loc) · 899 Bytes
/
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
from flask import Flask, jsonify
from match_getter import get_matches
from teams_getter import get_teams
from flask_cors import CORS
from utils.format_utils import format_url, format_team_name
app = Flask(__name__)
CORS(app)
@app.route('/get-teams/<string:league_url>', methods=['GET'])
def request_teams(league_url: str):
url = format_url(league_url)
return jsonify(get_teams(url)), 201
@app.route('/get-matches/<string:team_name>/<string:league_url>/<int:game_span>', methods=['GET'])
def request_matches(team_name: str, league_url: str, game_span: int):
team_name = format_team_name(team_name)
league_url = format_url(league_url)
matches_dict = []
matches = get_matches(team_name, league_url, game_span)
for match in matches:
matches_dict.append(match.to_dict())
return jsonify(matches_dict), 202
if __name__ == '__main__':
app.run(debug=True)