Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
topstreamsforgame_data = topstreamsforgame_response_json['data']
# Converting into a DataFrame
topstreamsforgame_df = pd.DataFrame.from_dict(json_normalize(topstreamsforgame_data), orient='columns')
# FOR loop to get top 25 streamers for rest of the games in our list
# To keep the dashboard lightweight and relevant, I am using only the Top 20 Games and Top 25 Streamers per game
for i in range(1,19) :
headers = {
'Authorization' : 'Bearer '+str(access_token),
}
topstreamsforgame_response = requests.get('https://api.twitch.tv/helix/streams?game_id='+str(topgames_df['id'][i])+'&first=25', headers=headers)
topstreamsforgame_response_json = json.loads(topstreamsforgame_response.text)
topstreamsforgame_data = topstreamsforgame_response_json['data']
topstreamsforgame_df_temp = pd.DataFrame.from_dict(json_normalize(topstreamsforgame_data), orient='columns')
frames = [topstreamsforgame_df, topstreamsforgame_df_temp]
topstreamsforgame_df = pd.concat(frames, ignore_index=True)
# Look at the data we retrieved
topstreamsforgame_df.info()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.