-
-
Notifications
You must be signed in to change notification settings - Fork 896
Expand file tree
/
Copy pathgameweek.py
More file actions
24 lines (17 loc) · 599 Bytes
/
gameweek.py
File metadata and controls
24 lines (17 loc) · 599 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
from datetime import datetime
import requests
import json
def get_recent_gameweek_id():
"""
Get's the most recent gameweek's ID.
"""
data = requests.get('https://fantasy.premierleague.com/api/bootstrap-static/')
data = json.loads(data.content)
gameweeks = data['events']
now = datetime.utcnow()
for gameweek in gameweeks:
next_deadline_date = datetime.strptime(gameweek['deadline_time'], '%Y-%m-%dT%H:%M:%SZ')
if next_deadline_date > now:
return gameweek['id'] - 1
if __name__ == '__main__':
print(get_recent_gameweek_id())