-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_helper.py
29 lines (23 loc) · 891 Bytes
/
io_helper.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
import os
import csv
# create file at file path if not already exists
def create_filepath_if_not_exists(filepath: str):
if not os.path.exists(filepath):
os.mkdir(filepath)
# read in file as list of its lines
def read_emotes(emotes_filepath: str):
emotes = []
create_filepath_if_not_exists(emotes_filepath)
with open(emotes_filepath, encoding="utf8") as emote_file:
emote_reader = csv.reader(emote_file)
for row in emote_reader:
emotes += row
return emotes
# read in all .txt files in given directory and return list of them
def read_input_files(input_directory: str):
text_channels = []
for file in os.listdir(input_directory):
if file.endswith(".txt"):
with open(input_directory + file, 'r', encoding="utf8") as text_file:
text_channels += [text_file.read()]
return text_channels