-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (28 loc) · 1.21 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
from flask import Flask, request, jsonify
import requests
app = Flask(__name__)
BASE_URL = 'https://api.football-data.org/v2'
API_KEY = 'e8a8543277f74feb9bd02db503fd8315' # Replace with your actual API key
headers = {'X-Auth-Token': API_KEY}
@app.route('/get_fixtures', methods=['GET'])
def get_fixtures():
league_id = request.args.get('league_id')
url = f'{BASE_URL}/competitions/{league_id}/matches'
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
fixtures = data['matches']
return jsonify({'fixtures': fixtures})
else:
return jsonify({'error': f"Failed to fetch data. Status code: {response.status_code}"}), 500
@app.route('/get_all_leagues', methods=['GET'])
def get_all_competitions():
url = 'https://api.football-data.org/v2/competitions'
response = requests.get(url, headers=headers)
if response.status_code == 200:
competitions = response.json() # Fix the typo here
return jsonify({'competitions': competitions})
else:
return jsonify({'error': f"Failed to fetch data. Status code: {response.status_code}"}), 500
if __name__ == '__main__':
app.run(debug=True)