-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_make2.py
44 lines (35 loc) · 1.34 KB
/
sample_make2.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
import re
import os
txt_files = os.listdir("samples/stories/test2/")
# print(txt_files)
# dictionary for one row keyboard
one_row = {"q": 1, "a": 1, "z": 1,
"w": 2, "s": 2, "x": 2,
"e": 3, "d": 3, "c": 3,
"r": 4, "f": 4, "v": 4,
"t": 5, "g": 5, "b": 5,
"y": 6, "h": 6, "n": 6,
"u": 7, "j": 7, "m": 7,
"i": 8, "k": 8,
"o": 9, "l": 9,
"p": 0}
with open("encrypted3.txt", "w") as f2:
for txt_file in txt_files:
with open("samples/stories/test2/"+txt_file, "r", encoding='utf-8') as f:
for line in f:
w_list = line.split()
for i, w in enumerate(w_list):
w = re.sub(r"[^a-zA-Z]", "", w)
word_to_num = ""
for c in w:
try:
word_to_num += str(one_row[c.lower()])
except KeyError:
break
if len(word_to_num) > 0:
if i < len(w_list)-1:
f2.write(word_to_num+" ")
else:
f2.write(word_to_num+"\n")
# f2.write("\n")
# print(output)