Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- v1.0 (9/5/19): twitch data-analysis from the csv file you can download from their website
- You can download the file you need here: https://www.twitch.tv/CHANNELNAME/dashboard/channel-analytics/
- The csv file is formatted in this way:
- Start Time,End Time,Average Viewers,Max. Viewers,Total Views,Unique Views,Minutes Watched,New Followers,Chatters,Chat Messages,Clips Created,Clip Views,Ad Breaks (Minutes),Minutes Streamed
- But in the future, it might vary. I'll try to keep this code updated.
- v1.1 (10/5/19): added matplotlib graphs for each category
- '''
- import matplotlib.pyplot as plt
- import numpy as np
- version = "1.1"
- def main():
- flag = True
- while(flag):
- graph_flag = True
- avg_viewers = []
- max_viewers = []
- minutes_streamed = []
- new_followers = []
- clips = []
- days = []
- months = []
- print("Twitch Analytics from csv")
- print("Version: " + version)
- filename = input("Insert filename or path:")
- if filename[-4:] != '.csv':
- filename = filename + '.csv'
- tmp = input("Would you like to see a graph of your stats?(y/n)")
- if tmp != 'y':
- graph_flag = False
- #leggo dal file
- with open(filename, "r") as f1:
- next(f1)
- for line in f1:
- a = line.split(',')
- #metto tutto in liste d'appoggio per chiarezza
- avg_viewers.append(float(a[2]))
- max_viewers.append(int(a[3]))
- minutes_streamed.append(int(a[-1]))
- new_followers.append(int(a[7]))
- clips.append(int(a[10]))
- #giorni
- b = a[1].split(" ")
- months.append(b[1])
- days.append(b[2])
- #stampo a console i dati
- print("\nStats for the period between " + days[0] + " " + months[0] + " and " + days[-1] + " " + months[-1])
- print("Average viewers: " + str(round(sum(avg_viewers)/len(avg_viewers), 3)))
- print("Viewers record: " + str(max(max_viewers)))
- print("Time you spent live-steaming: " + str(sum(minutes_streamed)) + " minutes (" + str(round(sum(minutes_streamed) / 60.0, 2)) + " hours)")
- print("Longest live-stream: " + str(max(minutes_streamed)) + "minutes (" + str(round(max(minutes_streamed) / 60.0 , 2)) + " hours)")
- print("New followers: " + str(sum(new_followers)))
- print("Clips generated: " + str(sum(clips)))
- if graph_flag:
- fig = plt.figure()
- avg = fig.add_subplot(711)
- tim = fig.add_subplot(713)
- fol = fig.add_subplot(715)
- clp = fig.add_subplot(717)
- #avg viewers
- avg.plot(avg_viewers , 'o', avg_viewers, '-')
- avg.plot(max_viewers, '--')
- avg.minorticks_on()
- avg.set_title("Average Viewers")
- avg.set_ylabel("Viewers")
- #minutes
- tim.plot(minutes_streamed , 'o', minutes_streamed, '-')
- tim.set_title("Minutes")
- tim.set_ylabel("Minutes")
- #followers
- fol.plot(new_followers)
- fol.set_title("New followers")
- fol.set_ylabel("Followers")
- #clips
- clp.plot(clips , 'o', clips, '-')
- clp.set_title("Clips Generated")
- clp.set_ylabel("Clips")
- plt.show()
- #flag e loop
- x = input("\nDo you have more files? (y/n)")
- print("")
- if (x != "y"):
- flag = False
- main()
Advertisement
Add Comment
Please, Sign In to add comment