-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.py
More file actions
38 lines (27 loc) · 959 Bytes
/
table.py
File metadata and controls
38 lines (27 loc) · 959 Bytes
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
import requests
import json
import pandas as pd
def get_data():
# URL of the JSON file
url = 'https://fantasy.premierleague.com/api/bootstrap-static/'
# Send a GET request to the URL
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Save the JSON content to a file
with open('data.json', 'w', encoding='utf-8') as file:
json.dump(response.json(), file, indent=4) # Save with formatting
print("JSON file downloaded and saved as 'data.json'")
else:
print(f"Failed to download JSON file. HTTP Status Code: {response.status_code}")
def get_teams():
with open('data.json', 'r', encoding='utf-8') as file:
data = json.load(file)
team = data['teams']
df = pd.DataFrame(team)
table = df[['name','played','points','short_name']]
print(table)
def main():
...
if __name__ == "__main__":
get_teams()