Skip to content

Instantly share code, notes, and snippets.

View kaivalyapowale's full-sized avatar

Kaivalya kaivalyapowale

View GitHub Profile
@kaivalyapowale
kaivalyapowale / access_token_spotify.py
Created January 19, 2020 01:16
Function to get Spotify access token
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 January 19, 2020 01:05
Function for base64 encoding of the Spotify Client IDs
# 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 January 19, 2020 00:57
Import Libraries for Spotify API (auth)
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 December 18, 2019 03:33
Final Code for Twitch Dashboard
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 December 18, 2019 03:06
Top Streams for a game Twitch
# 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 December 17, 2019 15:08
Get Top 100 Games by Number of Viewers Twitch
# 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 December 18, 2019 03:08
Importing libraries for Twitch API
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 December 17, 2019 14:47
Authentication for Twitch API
#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