Skip to content

Instantly share code, notes, and snippets.

@eado
Last active May 28, 2020 17:33
Show Gist options
  • Save eado/7ff9b428453c53e60316bf1a349d7474 to your computer and use it in GitHub Desktop.
Save eado/7ff9b428453c53e60316bf1a349d7474 to your computer and use it in GitHub Desktop.
Using Discord's data request bundle, this determines the amount of words said said by the user per channel and in total.
import json
from pathlib import Path
references = json.loads(open('messages/index.json').read())
pathlist = Path("messages").glob("**/messages.csv")
channel_dict = {}
count = 0
for path in pathlist:
identifier = str(path).split("/")[1]
name = references[identifier]
if not name:
name = ""
with open(str(path), 'r') as file:
data = file.read()
messages = data.split("\n")[1::]
file_count = 0
for message in messages:
initial_index = 52
if message and message[0] == '>':
initial_index = 1
message_content = message[initial_index:-1].replace("\"", "")
file_count += len(message_content.split(" "))
if channel_dict.get(name):
channel_dict[name] += file_count
else:
channel_dict[name] = file_count
count += file_count
for (key, value) in sorted(channel_dict.items(), key=lambda x: x[1], reverse=True):
if key == "":
key = "Unknown"
print(key + ": " + str(value))
print("\n")
print("Total words: " + str(count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment