Created
February 25, 2025 20:25
-
-
Save NickDeckerDevs/97090192640895f12524e7ee23da6f45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import pandas as pd | |
import time | |
def fetch_players(gender): | |
base_url = "https://drop-api.ea.com/rating/ea-sports-fc?locale=en&limit=100&gender=" | |
offset = 0 | |
all_players = [] | |
while True: | |
url = f"{base_url}{gender}&offset={offset}" | |
response = requests.get(url) | |
if response.status_code != 200: | |
print(f"Failed to fetch data: {response.status_code}") | |
break | |
data = response.json() | |
if "items" not in data or not data["items"]: | |
break # No more data to fetch | |
all_players.extend(data["items"]) | |
print(f"Fetched {len(data['items'])} players, total so far: {len(all_players)}") | |
offset += 100 # Move to the next page | |
time.sleep(1) # Avoid rate limiting | |
return pd.DataFrame(all_players) | |
# Fetch both male and female players | |
male_players = fetch_players(0) | |
female_players = fetch_players(1) | |
# Combine and save to CSV | |
all_players = pd.concat([male_players, female_players], ignore_index=True) | |
male_players.to_csv("male_players.csv", index=False) | |
female_players.to_csv("female_players.csv", index=False) | |
all_players.to_csv("all_players.csv", index=False) | |
print("Player data fetching complete! CSV files saved.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment