Advertisement
Guest User

Chatspeed Youtube Twitch

a guest
Dec 4th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | Software | 0 0
  1. from chat_downloader import ChatDownloader
  2. from datetime import datetime, timezone
  3. import matplotlib.pyplot as plt
  4.  
  5. url = 'https://www.twitch.tv/videos/1988911250'
  6. chat = ChatDownloader().get_chat(url)       # create a generator
  7.  
  8. message_count = 0
  9.  
  10. # Initialize a dictionary to store message counts for each minute
  11. messages_per_minute = {}
  12.  
  13. # Initialize a set to store unique usernames
  14. unique_usernames = set()
  15.  
  16. # Iterate over messages to count them
  17. for message in chat:
  18.  
  19.     # Capture the username for the message
  20.     try:
  21.         username = message['author']['name']
  22.     except KeyError:
  23.         # Handle the case where 'author' key is not present
  24.         username = 'Unknown'
  25.  
  26.     unique_usernames.add(username)
  27.  
  28.     # Extract the minute from the message timestamp
  29.     message_time =  datetime.fromtimestamp(message['time_in_seconds'], tz=timezone.utc)
  30.     minute_key = message_time.strftime('%H:%M')
  31.  
  32.     # Increment the counter for the corresponding minute
  33.     messages_per_minute[minute_key] = messages_per_minute.get(minute_key, 0) + 1
  34.  
  35.     # Increment the overall message count
  36.     message_count += 1
  37.  
  38. # Print the total message count
  39. print(f'Total Messages in the VOD: {message_count}')
  40.  
  41. # Print the total number of unique usernames
  42. print(f'Total Unique Usernames: {len(unique_usernames)}')
  43.  
  44. # Print the message count for each minute
  45. for minute, count in messages_per_minute.items():
  46.     print(f'{minute}: {count} messages')
  47.  
  48. # Plot the message count for each minute
  49. minutes = list(messages_per_minute.keys())
  50. message_counts = list(messages_per_minute.values())
  51.  
  52. plt.bar(minutes, message_counts)
  53. plt.xlabel('Minute')
  54. plt.ylabel('Number of Messages')
  55. plt.title('Number of Messages Every Minute')
  56. plt.xticks(rotation=45, ha='right')
  57. plt.xticks([])
  58. plt.tight_layout()
  59. plt.show()
  60.  
Tags: Chatspeed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement