-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefs.py
172 lines (143 loc) · 4.65 KB
/
defs.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import tkinter.messagebox as mb
bin = ['.', '\'', '\"', '[', ']', '(', ')', '{', '}', '<', '>', ':', ',', '-', '!', '?', ';', '/', '\\',
'@', '#', '$', '%', '^', '&', '*', '+', '=', '_', '|', '~', '`', '\n']
def show_info():
mb.showinfo("обновление списка", "после обновления списка необходимо перезагрузить преложение")
def save_data(data_loc):
file = open("data.txt", "w")
for elem in data_loc:
file.write(elem + " " + str(data_loc[elem]) + "\n")
file.close()
def load_text_data(lines):
text_data = []
i = 0
while i < len(lines):
lines[i] = lines[i].replace('\n', '')
for elem in bin:
lines[i] = lines[i].replace(elem, '')
if lines[i] == '':
lines.pop(i)
i -= 1
i += 1
if i % 2 != 0:
text_data.append([lines[i - 1], lines[i]])
return text_data
def load_data_best():
loc_data = []
def load_data():
data_loc = {}
file = open("data.txt", "r").readlines()
for elem in file:
elem = elem.replace("\n", "")
elem = elem.split()
data_loc[elem[0]] = int(elem[1])
# print(data_loc)
return data_loc
def learn_up(line):
data_loc = load_data()
check = line.split(" ")
if line[len(line) - 1] == " ":
line = line[:-1]
for elem in bin:
line = line.replace(elem, '')
if len(check) == 1:
if line in data_loc:
data_loc[line] += 1
else:
data_loc[line] = 1
save_data(data_loc)
data_loc = load_data()
if data_loc[line] > 100:
data_loc[line] = 100
print("[LOG] СЛОВАРЬ ПОПОЛНЕН СЛОВОМ (" + line + ")")
# print(data_loc)
elif len(check) > 1:
line = line.split(" ")
new = 0
for word in line:
if word in data_loc:
data_loc[word] += 1
else:
data_loc[word] = 1
save_data(data_loc)
data_loc = load_data()
new += 1
if data_loc[word] > 100:
data_loc[word] = 100
print("[LOG] СЛОВАРЬ ПОПОЛНЕН СПИСКОМ СЛОВ #" + str(new))
# print(data_loc)
return data_loc
def learn_down(line):
data_loc = load_data()
if line[len(line) - 1] == " ":
line = line[:-1]
for elem in bin:
line = line.replace(elem, '')
check = line.split(" ")
if len(check) == 1:
if line in data_loc:
data_loc[line] -= 1
else:
data_loc[line] = -1
save_data(data_loc)
data_loc = load_data()
if data_loc[line] < -50:
data_loc[line] = -50
print("[LOG] СЛОВАРЬ ПОПОЛНЕН СЛОВОМ (" + line + ")")
# print(data_loc)
elif len(check) > 1:
line = line.split(" ")
new = 0
for word in line:
if word in data_loc:
data_loc[word] -= 1
else:
data_loc[word] = 0
save_data(data_loc)
data_loc = load_data()
new += 1
if data_loc[word] < -30:
data_loc[word] = -30
print("[LOG] СЛОВАРЬ ПОПОЛНЕН СПИСКОМ СЛОВ #" + str(new))
# print(data_loc)
return data_loc
def rec(line):
data = load_data()
KH = 0
k = 0
for elem in line:
try:
KH += data[elem]
k += 1
except KeyError:
data = learn_up(elem)
print("[LOG] СЛОВАРЬ ПОПОЛНЕН")
# print(data)
return KH / k
def load_rec():
file = open("C:\\Users\\User\\Desktop\\shar_best.txt", 'w', encoding='utf-8')
lines = open("C:\\Users\\User\\Desktop\\shar.txt", encoding='utf-8').readlines()
text_data = load_text_data(lines)
# print(text_data)
for i in range(len(text_data)):
try:
buf = text_data[i][0].replace('Вопрос ', '')
if rec(buf.split()) > 40:
file.write(text_data[i][0] + '\n' + text_data[i][1] + '\n')
print("[LOG] Список реков обновлен")
except ZeroDivisionError:
pass
file.close()
show_info()
def get_best():
lines = open("C:\\Users\\User\\Desktop\\shar_best.txt", encoding='utf-8').readlines()
data_best = load_text_data(lines)
return data_best
def save_id(id):
file = open("save.txt", 'w')
file.write(id)
file.close()
def load_id(id):
file = open("save.txt").readline()
id = int(file.replace('\n', ''))
return id