forked from nathantfrank/ircProjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_wof.py
31 lines (27 loc) · 883 Bytes
/
save_wof.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
import json
from string import capwords
import re
line_type = ""
hm_dict = {}
with open("wof_list.txt", "r") as read_file:
for line in read_file:
line = line.strip()
if "-Category-" in line:
line_type = "category"
continue
elif "-Phrases-" in line:
line_type = "phrases"
continue
if line_type == "category":
current_category = line
hm_dict[line] = []
elif line_type == "phrases":
line_list = []
for word in re.split(" ", line):
if "." in word:
line_list.append(word.upper())
else:
line_list.append(word.capitalize())
hm_dict[current_category].append(" ".join(line_list))
with open("hm_phrase_dict.json", "w") as out_file:
json.dump(hm_dict, out_file)