1
0
Fork 0

解决简单单词未成功加入生词簿,但依旧显示“added ****.”的提示信息

BUG###-nizhouting
倪周挺 2024-06-28 20:47:21 +08:00
parent d8af2a7e54
commit 750e67ef6b
2 changed files with 21 additions and 9 deletions

View File

@ -64,10 +64,9 @@ def load_record(pickle_fname):
def save_frequency_to_pickle(d, pickle_fname): def save_frequency_to_pickle(d, pickle_fname):
f = open(pickle_fname, 'wb') f = open(pickle_fname, 'wb')
exclusion_lst = ['one', 'no', 'has', 'had', 'do', 'that', 'have', 'by', 'not', 'but', 'we', 'this', 'my', 'him', 'so', 'or', 'as', 'are', 'it', 'from', 'with', 'be', 'can', 'for', 'an', 'if', 'who', 'whom', 'whose', 'which', 'the', 'to', 'a', 'of', 'and', 'you', 'i', 'he', 'she', 'they', 'me', 'was', 'were', 'is', 'in', 'at', 'on', 'their', 'his', 'her', 's', 'said', 'all', 'did', 'been', 'w']
d2 = {} d2 = {}
for k in d: for k in d:
if not k in exclusion_lst and not k.isnumeric() and not len(k) < 2: if not k.isnumeric() and not len(k) < 2:
d2[k] = list(sorted(d[k])) # 原先这里是d2[k] = list(sorted(set(d[k]))) d2[k] = list(sorted(d[k])) # 原先这里是d2[k] = list(sorted(set(d[k])))
pickle.dump(d2, f) pickle.dump(d2, f)
f.close() f.close()

View File

@ -178,14 +178,27 @@ def user_mark_word(username):
d = load_freq_history(user_freq_record) d = load_freq_history(user_freq_record)
lst_history = pickle_idea2.dict2lst(d) lst_history = pickle_idea2.dict2lst(d)
lst = [] lst = []
for word in request.form.getlist('marked'): # pickle_idea2.save_frequency_to_pickle中设置的较为简单的无法加入生词簿的单词,虽然生词簿未添加但添加后顶部依然会显示"Added ***"的信息
lst.append((word, [get_time()])) exclusion_lst = ['one', 'no', 'has', 'had', 'do', 'that', 'have', 'by', 'not', 'but', 'we', 'this', 'my',
d = pickle_idea2.merge_frequency(lst, lst_history) 'him', 'so', 'or', 'as', 'are', 'it', 'from', 'with', 'be', 'can', 'for', 'an', 'if',
if len(lst_history) > 999: 'who', 'whom', 'whose', 'which', 'the', 'to', 'a', 'of', 'and', 'you', 'i', 'he', 'she',
flash('You have way too many words in your difficult-words book. Delete some first.') 'they', 'me', 'was', 'were', 'is', 'in', 'at', 'on', 'their', 'his', 'her', 's', 'said',
'all', 'did', 'been', 'w']
add = request.form.getlist('marked')
trueadd = []
for word in add:
if word not in exclusion_lst:
trueadd.append(word)
lst.append((word, [get_time()]))
if len(trueadd) > 0: # 如果有单词被添加
d = pickle_idea2.merge_frequency(lst, lst_history)
if len(lst_history) > 999:
flash('You have way too many words in your difficult-words book. Delete some first.')
else:
pickle_idea2.save_frequency_to_pickle(d, user_freq_record)
flash('Added %s.' % (', '.join(trueadd))) # 显示添加的单词
else: else:
pickle_idea2.save_frequency_to_pickle(d, user_freq_record) flash('No new words were added. All words were either too simple or already in your list.') # 没有单词被添加
flash('Added %s.' % (', '.join(request.form.getlist('marked'))))
return redirect(url_for('user_bp.userpage', username=username)) return redirect(url_for('user_bp.userpage', username=username))
else: else:
return 'Under construction' return 'Under construction'