forked from Flerex/wordle.es
-
Notifications
You must be signed in to change notification settings - Fork 0
/
words.py
67 lines (45 loc) · 1.13 KB
/
words.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
import re
# %%
dict_ = []
with open("./public/main.dict", "r") as f:
dict_ = f.read().splitlines()
# %%
all_words = []
for item in dict_:
parts = item.split("/")
if len(parts) == 1:
word = parts[0]
all_words.append(word)
if len(parts) == 2:
variations = parts[1]
# Add regular word
word = parts[0]
all_words.append(word)
if "S" in variations:
word = parts[0] + "s"
all_words.append(word)
# %% Clean up words
def remove_accents(old):
"""
Removes common accent characters, lower form.
Uses: regex.
"""
new = old.lower()
new = re.sub(r"[àáâãäå]", "a", new)
new = re.sub(r"[èéêë]", "e", new)
new = re.sub(r"[ìíîï]", "i", new)
new = re.sub(r"[òóôõö]", "o", new)
new = re.sub(r"[ùúûü]", "u", new)
return new
all_words = [remove_accents(w.lower()) for w in all_words]
# %%
words_5 = []
for word in all_words:
if len(word) == 5:
words_5.append(word)
# %%
with open("./public/palabras_5.json", "w") as f:
json.dump(words_5, f, ensure_ascii=False)
# %%