Skip to content

Commit

Permalink
[add] get_player
Browse files Browse the repository at this point in the history
  • Loading branch information
Hwang-Jaeryeong committed Jan 22, 2024
1 parent 90f5c49 commit bcce4a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Binary file modified info/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified info/__pycache__/views.cpython-311.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion info/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import path
from .views import get_fixtures, get_predictions, GetLineupPredictions,GetFixtureEvents, GetStandings, get_top_scorers, get_match, get_allmatches, get_fixture_statistics
from .views import get_fixtures, get_predictions, GetLineupPredictions,GetFixtureEvents, GetStandings, get_top_scorers, get_match, get_allmatches, get_fixture_statistics, get_players

urlpatterns = [
path('get_fixtures/', get_fixtures, name='get_fixtures'),
Expand All @@ -11,4 +11,5 @@
path('get_match/', get_match, name='get_match'),
path('get_allmatches/', get_allmatches, name='get_allmatches'),
path('fixture_statistics/<int:fixture_id>/', get_fixture_statistics, name='get_fixture_statistics'),
path('get_players/', get_players, name='get_players'),
]
26 changes: 25 additions & 1 deletion info/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,28 @@ def get_fixture_statistics(request, fixture_id):
data = response.json()
return JsonResponse(data)
except requests.exceptions.RequestException as e:
return JsonResponse({'error': str(e)})
return JsonResponse({'error': str(e)})


from django.http import JsonResponse
import requests

def get_players(request):
url = 'https://api-football-v1.p.rapidapi.com/v3/players'
params = {
'team': request.GET.get('team', '47'),
'league': '39',
'season': '2023',
}
headers = {
'X-RapidAPI-Key': '24d52a531dmsh693cfe90d613d38p1a8e61jsn6a752b08adf5',
'X-RapidAPI-Host': 'api-football-v1.p.rapidapi.com',
}

try:
response = requests.get(url, params=params, headers=headers)
response.raise_for_status() # Raise an exception for bad responses
data = response.json()
return JsonResponse(data)
except requests.exceptions.RequestException as e:
return JsonResponse({'error': str(e)})

0 comments on commit bcce4a9

Please sign in to comment.