-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordlistparser.py
More file actions
63 lines (41 loc) · 1.35 KB
/
Copy pathwordlistparser.py
File metadata and controls
63 lines (41 loc) · 1.35 KB
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
from unidecode import unidecode
import csv
from pprint import pprint
import json
import sys
def get_word_list(language="en"):
word_bank = ""
freq_bank = ""
supported_languages = ['br', 'en']
if language not in supported_languages:
language = 'en'
print("updating word list to language: " + language)
if language == 'br':
word_bank = "dicio.txt"
freq_bank = "data.txt"
elif language == 'en':
word_bank = "english-words.txt"
freq_bank = "data.txt"
#if len(sys.argv) > 1:
# word_bank = sys.argv[1]
f = open(word_bank, "r", encoding='utf-8')
possible_words = []
for word in f:
word = unidecode(word[:-1].lower())
if len(word) != 5: continue
possible_words.append(word)
f.close()
f = open("banco-palavras.txt", "w", encoding='utf-8')
for word in possible_words:
f.write(word + "\n")
f.close()
frequencies = {}
with open(freq_bank, encoding='utf-8') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for idx, row in enumerate(csv_reader):
if idx == 0: continue
word = unidecode(row[0].lower())
if len(word) != 5: continue
frequencies[word] = int(row[1])
with open('frequencies.json', 'w') as f:
json.dump(frequencies, f)