Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from chat_downloader import ChatDownloader
- from datetime import datetime, timezone
- import matplotlib.pyplot as plt
- url = 'https://www.twitch.tv/videos/1988911250'
- chat = ChatDownloader().get_chat(url) # create a generator
- message_count = 0
- # Initialize a dictionary to store message counts for each minute
- messages_per_minute = {}
- # Initialize a set to store unique usernames
- unique_usernames = set()
- # Iterate over messages to count them
- for message in chat:
- # Capture the username for the message
- try:
- username = message['author']['name']
- except KeyError:
- # Handle the case where 'author' key is not present
- username = 'Unknown'
- unique_usernames.add(username)
- # Extract the minute from the message timestamp
- message_time = datetime.fromtimestamp(message['time_in_seconds'], tz=timezone.utc)
- minute_key = message_time.strftime('%H:%M')
- # Increment the counter for the corresponding minute
- messages_per_minute[minute_key] = messages_per_minute.get(minute_key, 0) + 1
- # Increment the overall message count
- message_count += 1
- # Print the total message count
- print(f'Total Messages in the VOD: {message_count}')
- # Print the total number of unique usernames
- print(f'Total Unique Usernames: {len(unique_usernames)}')
- # Print the message count for each minute
- for minute, count in messages_per_minute.items():
- print(f'{minute}: {count} messages')
- # Plot the message count for each minute
- minutes = list(messages_per_minute.keys())
- message_counts = list(messages_per_minute.values())
- plt.bar(minutes, message_counts)
- plt.xlabel('Minute')
- plt.ylabel('Number of Messages')
- plt.title('Number of Messages Every Minute')
- plt.xticks(rotation=45, ha='right')
- plt.xticks([])
- plt.tight_layout()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement