Skip to content

Instantly share code, notes, and snippets.

Avatar

Kaivalya kaivalyapowale

View GitHub Profile
@kaivalyapowale
kaivalyapowale / access_token_spotify.py
Created Jan 19, 2020
Function to get Spotify access token
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'
}
@kaivalyapowale
kaivalyapowale / base64_encode_spotify.py
Created Jan 19, 2020
Function for base64 encoding of the Spotify Client IDs
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)
@kaivalyapowale
kaivalyapowale / import_libraries_spotify_auth.py
Created Jan 19, 2020
Import Libraries for Spotify API (auth)
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
@kaivalyapowale
kaivalyapowale / final_dashboard_twitch.py
Created Dec 18, 2019
Final Code for Twitch Dashboard
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)
@kaivalyapowale
kaivalyapowale / top_streams_twitch.py
Created Dec 18, 2019
Top Streams for a game Twitch
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
@kaivalyapowale
kaivalyapowale / get_top_games_twitch.py
Created Dec 17, 2019
Get Top 100 Games by Number of Viewers Twitch
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
@kaivalyapowale
kaivalyapowale / import_libraries_twitch.py
Last active Dec 18, 2019
Importing libraries for Twitch API
View import_libraries_twitch.py
import json
import requests
import pandas as pd
from pandas.io.json import json_normalize
import time
import threading
@kaivalyapowale
kaivalyapowale / authentication.py
Last active Dec 17, 2019
Authentication for Twitch API
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
You can’t perform that action at this time.