-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsing.py
67 lines (56 loc) · 1.43 KB
/
parsing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import json
''' dump taken 2021-05-08:
general
newbie
salt
grindhouse
minecraft
blowshitup
serious
warroom
pocketdefense
wingmates
shootblues
'''
dht_input = 'goose-2022-04-19.txt'
with open(dht_input, 'r', encoding="utf-8") as f:
dump = json.load(f)
discord_users = dump['meta']['users']
uids = {}
unums = {}
usernames = {}
count = 0
for uid in discord_users:
name = discord_users[uid]['name']
if 'tag' in discord_users[uid]:
tag = discord_users[uid]['tag']
else:
tag = None
uids[uid] = {'name': name, 'tag': tag, 'unum': count}
unums[count] = {'name': name, 'tag': tag, 'uid': uid}
usernames[name] = {'uid': uid, 'tag': tag}
count += 1
discord_channels = dump['meta']['channels']
channel_ids = {}
for cid in discord_channels:
channel_ids[cid] = discord_channels[cid]['name']
textout = ''
message_dump = dump['data']
for channel in message_dump:
msgs = message_dump[channel]
prev_msg = None
for msg in msgs:
name = unums[msgs[msg]['u']]['name']
if 'm' in msgs[msg]:
message = msgs[msg]['m']
else:
pass
if message == prev_msg:
continue
else:
prev_msg = message
textout += name + ': ' + message + '\n'
with open('parsed_discord.txt', 'w', encoding="utf-8") as outfile:
outfile.write(textout)
with open('usercache.json', 'w', encoding='utf-8') as userdump:
json.dump(usernames, userdump)