WIP:BUG###-nizhouting #150

Draft
nizhouting wants to merge 3 commits from nizhouting/EnglishPal:BUG###-nizhouting into Alpha-snapshot20230621OK
3 changed files with 23 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

@ -0,0 +1,2 @@
def test_add_simple_word_to_vocabulary(driver, URL):
return

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 ***"的信息
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']
add = request.form.getlist('marked')
trueadd = []
for word in add:
if word not in exclusion_lst:
trueadd.append(word)
lst.append((word, [get_time()])) lst.append((word, [get_time()]))
if len(trueadd) > 0: # 如果有单词被添加
d = pickle_idea2.merge_frequency(lst, lst_history) d = pickle_idea2.merge_frequency(lst, lst_history)
if len(lst_history) > 999: if len(lst_history) > 999:
flash('You have way too many words in your difficult-words book. Delete some first.') flash('You have way too many words in your difficult-words book. Delete some first.')
else: else:
pickle_idea2.save_frequency_to_pickle(d, user_freq_record) pickle_idea2.save_frequency_to_pickle(d, user_freq_record)
flash('Added %s.' % (', '.join(request.form.getlist('marked')))) flash('Added %s.' % (', '.join(trueadd))) # 显示添加的单词
else:
flash('No new words were added.') # 没有单词被添加
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'