diff --git a/app/pickle_idea2.py b/app/pickle_idea2.py index 0da55bc..4c93985 100644 --- a/app/pickle_idea2.py +++ b/app/pickle_idea2.py @@ -64,10 +64,9 @@ def load_record(pickle_fname): def save_frequency_to_pickle(d, pickle_fname): 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 = {} 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]))) pickle.dump(d2, f) f.close() diff --git a/app/test/test_bug###_nizhouting.py b/app/test/test_bug###_nizhouting.py new file mode 100644 index 0000000..3303348 --- /dev/null +++ b/app/test/test_bug###_nizhouting.py @@ -0,0 +1,2 @@ +def test_add_simple_word_to_vocabulary(driver, URL): + return \ No newline at end of file diff --git a/app/user_service.py b/app/user_service.py index 27323b8..eeca743 100644 --- a/app/user_service.py +++ b/app/user_service.py @@ -178,14 +178,27 @@ def user_mark_word(username): d = load_freq_history(user_freq_record) lst_history = pickle_idea2.dict2lst(d) lst = [] - for word in request.form.getlist('marked'): - lst.append((word, [get_time()])) - 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.') + # 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()])) + 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: - pickle_idea2.save_frequency_to_pickle(d, user_freq_record) - flash('Added %s.' % (', '.join(request.form.getlist('marked')))) + flash('No new words were added.') # 没有单词被添加 return redirect(url_for('user_bp.userpage', username=username)) else: return 'Under construction'