Created
July 4, 2020 13:01
-
-
Save derek-adair/d64f6c076aa8eb90f0f08a6b1a2e3c4c to your computer and use it in GitHub Desktop.
Uses new NFL API to pull down 2020 week 1 schedule
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 json | |
import requests | |
url = "https://api.nfl.com/v1/reroute" | |
# TODO: resolve if DNT or x-domain-id are necessary. pulled them from chrome inspector | |
payload = 'grant_type=client_credentials' | |
headers = { | |
'DNT': '1', | |
'x-domain-id': '100', | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
response = requests.request("POST", url, headers=headers, data = payload) | |
access_token = json.loads(response.content)['access_token'] | |
# this query can be customized to return different data | |
# the line below will return 2019 week 1 results | |
# url = "https://api.nfl.com/v3/shield/?query=query{viewer{gameDetailsByIds(ids:[\"10160000-0579-156c-c1e2-24a16164d808\",\"10160000-0579-1456-122e-a499416e9643\",\"10160000-0579-1386-265b-4eb8c397806f\",\"10160000-0579-12d8-bb4a-d7a447161b3e\",\"10160000-0579-118b-3c8b-c2da80430da7\",\"10160000-0579-1049-369d-40104333e452\",\"10160000-0579-0943-6390-152ae4e3070f\",\"10160000-0579-0857-d2d2-30a8e1143954\",\"10160000-0579-0745-9311-a4adde960c3f\",\"10160000-0579-0647-b2a2-599c7c0b47ed\",\"10160000-0579-055e-7350-c0a2552a523f\",\"10160000-0579-0420-7eda-cfc27c838aeb\",\"10160000-0579-0376-f060-48ba658e0b31\",\"10160000-0579-02bc-e447-a1723e8641f6\",\"10160000-0579-01d7-059f-06001dedfbc7\",\"10160000-0579-00cc-9a8c-d465ab211561\"]){id,phase,homePointsTotal,visitorPointsTotal,phase gameClock period possessionTeam{abbreviation}yardsToGo down distance stadium weather{location}yardLine redzone}}}&variables=null" | |
# this will return the 2020 week 1 schedule | |
url = "https://api.nfl.com/v3/shield/?query=query{viewer{league{games(first:100,week_seasonValue:2020,week_seasonType:REG,week_weekValue:1,){edges{cursor node{id esbId gameDetailId gameTime gsisId networkChannels venue{fullName city state}awayTeam{nickName id abbreviation franchise{currentLogo{url}}}homeTeam{nickName id abbreviation franchise{currentLogo{url}}}slug}}}}}}&variables=null" | |
payload = {} | |
headers = { | |
'Content-Type': 'application/json', | |
'Authorization': f'Bearer {access_token}' | |
} | |
sched_resp = requests.request("GET", url, headers=headers, data = payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's a plugin for an IRC bot I help maintain, so just easier to keep it all maintained in one spot