Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import datetime
- # Set up API endpoint and headers
- url = "https://v3.football.api-sports.io/"
- endpoint = "fixtures"
- headers = {
- "x-rapidapi-host": "v3.football.api-sports.io",
- "x-rapidapi-key": "YOUR_API_KEY"
- }
- # Set up query parameters
- params = {
- "league": "301",
- "season": "2023",
- "dateFrom": "START_DATE",
- "dateTo": "END_DATE",
- "timezone": "America/Bogota"
- }
- # Make the API request
- response = requests.get(url + endpoint, headers=headers, params=params)
- # Convert the response to a JSON object
- data = json.loads(response.text)
- # Parse the data and extract relevant information
- for match in data["response"]:
- # Get the match ID
- match_id = match["fixture"]["id"]
- # Get the match date and convert it to a datetime object
- match_date_str = match["fixture"]["date"]
- match_date = datetime.datetime.strptime(match_date_str, "%Y-%m-%dT%H:%M:%S+00:00")
- # Get the home and away team IDs
- home_team_id = match["teams"]["home"]["id"]
- away_team_id = match["teams"]["away"]["id"]
- # Get the scores for the match
- home_score = match["goals"]["home"]
- away_score = match["goals"]["away"]
- # Get the ball possession for the home and away teams
- home_possession = match["statistics"]["possession"]["home"]
- away_possession = match["statistics"]["possession"]["away"]
- # Get the yellow cards for the home and away teams
- home_yellowcards = match["statistics"]["yellowcards"]["home"]
- away_yellowcards = match["statistics"]["yellowcards"]["away"]
- # Determine which team had more yellow cards and more ball possession
- if home_yellowcards > away_yellowcards:
- most_yellowcards_team_id = home_team_id
- elif away_yellowcards > home_yellowcards:
- most_yellowcards_team_id = away_team_id
- else:
- most_yellowcards_team_id = None
- if home_possession > away_possession:
- more_possession_team_id = home_team_id
- elif away_possession > home_possession:
- more_possession_team_id = away_team_id
- else:
- more_possession_team_id = None
- # Insert the match data into the database
- # INSERT INTO gnspartido (partido_id, partido_fecha, partido_marcadorlocal,
- # partido_marcadorvisitante, partido_resultado, equipo_local_id, equipo_visitante_id,
- # equipo_id_amarillas, equipo_id_posesion, partido_zonah, partido_automatizacionid)
- # VALUES (match_id, match_date, home_score, away_score, 'L' if home_score < away_score else 'V' if home_score > away_score else 'E',
- # home_team_id, away_team_id, most_yellowcards_team_id, more_possession_team_id, -5, 'API-{}'.format(match_id))
- print(f"Match ID: {match_id}")
- print(f"Match Date: {match_date}")
- print(f"Home Team ID: {home_team
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement