View access_token_spotify.py
def accesstoken(client_id, client_secret): | |
header_string= base64_encode(client_id,client_secret) | |
headers = { | |
'Authorization': 'Basic '+header_string, | |
} | |
data = { | |
'grant_type': 'client_credentials' | |
} | |
View base64_encode_spotify.py
# Defining base64 encoding of the IDs | |
def base64_encode(client_id,client_secret): | |
encodedData = base64.b64encode(bytes(f"{client_id}:{client_secret}", "ISO-8859-1")).decode("ascii") | |
authorization_header_string = f"{encodedData}" | |
return(authorization_header_string) |
View import_libraries_spotify_auth.py
import pandas as pd | |
import requests | |
import json | |
from pandas.io.json import json_normalize | |
import time | |
import base64 |
View final_dashboard_twitch.py
def twitch(): | |
threading.Timer(60.0, twitch).start() | |
# Top Games | |
headers = { | |
'Authorization' : 'Bearer '+str(access_token), | |
} | |
games_response = requests.get('https://api.twitch.tv/helix/games/top?first=100', headers=headers) | |
games_response_json = json.loads(games_response.text) |
View top_streams_twitch.py
# I am getting only the top 25 streamers for the first game | |
headers = { | |
'Authorization' : 'Bearer '+str(access_token), | |
} | |
topstreamsforgame_response = requests.get('https://api.twitch.tv/helix/streams?game_id='+str(topgames_df['id'][0])+'&first=25', headers=headers) | |
# Load the JSON | |
topstreamsforgame_response_json = json.loads(topstreamsforgame_response.text) | |
# Extracting data from the JSON |
View get_top_games_twitch.py
# Getting data for Top 100 Games by number of viewers | |
# Default response is for 20 games so you will have to set the parameter 'first to 100' | |
headers = { | |
'Authorization' : 'Bearer '+str(access_token), | |
} | |
games_response = requests.get('https://api.twitch.tv/helix/games/top?first=100', headers=headers) | |
# The response will be a JSON which will include the response data and the pagination cursor | |
# We need to extract the data from the JSON and convert it into a pandas dataframe |
View import_libraries_twitch.py
import json | |
import requests | |
import pandas as pd | |
from pandas.io.json import json_normalize | |
import time | |
import threading |
View authentication.py
#Client ID: --***--- | |
#Client Secret: ---***--- | |
#Client ID and Client Secret are sensititve and you should not share them | |
client_id= <yourclientid> | |
client_secret= <yourclientsecret> | |
#Request for the access code using requests library | |
#I have chosen this method of authentication with my goal in mind |