-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaner4.py
54 lines (38 loc) · 1.84 KB
/
cleaner4.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
# Jeannie Kim 9/2/21
# cleaner 3 but it writes to a new file (so that we can manually review the text)
import os, sys
with open('txtfiles/just-hanging-out 2.txt', 'r', encoding="utf8") as a: # first, read txt file into a list
lines = a.readlines()
print(lines)
# want to get list in format:
# message preceding aerin's, aerin's reply, ... ad nauseum
# it's easy to get next dialogue... how to get previous?
# idea: make list of tuples containing [(speaker, dialogue),...]
# previous tuples are accessible w/index
totalChat = list() # the big list
for i in range(len(lines)): # each line; i = line number
strdialogue = "" # initalize string for each dialogue
j = 0
discordname = lines[i][21:-1] # index of discord name in file
if lines[i][0] == "[":
while lines[i+j] != "\n" and i + j < len(lines)-1: # while the line isn't blank and the index is not out of bounds
strdialogue += lines[i+j+1].strip() + "\n" # add line to string
j += 1
#print(strdialogue,end='') # extra spaces was due to print()
totalChat.append((discordname,strdialogue.strip()))
print(totalChat)
# and now:
# go through totalChat, find aerin's dialogue, find dialogue before aerin's, append dialogues to aerinChat
aerinChat = list()
for i in range(len(totalChat)):
if totalChat[i][0] == "ragdoll kitten#9205" and i > 0: # first item in tuple is speaker
# can't be first item (as it takes previous item)
if totalChat[i-1][0] != "ragdoll kitten#9205":
aerinChat.append(totalChat[i-1][1]) # others' dialogue
aerinChat.append(totalChat[i][1]) # aerin's response
print(aerinChat)
with open('aconvoclean1.txt', 'w', encoding="utf8") as w: # 'w' write
for i in range(len(aerinChat)):
w.write(aerinChat[i]+"\n") # write list item
i+=1
#cleaner3('fullchat1.txt')