From 46d17933973109ef8c7fd00ee046f6e1a869bedd Mon Sep 17 00:00:00 2001 From: Lan Hui <1348141770@qq.com> Date: Mon, 2 Sep 2024 15:16:11 +0800 Subject: [PATCH] Fix Bug 563 --- app/pickle_idea2.py | 2 +- app/user_service.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/pickle_idea2.py b/app/pickle_idea2.py index 0da55bc..b5716bf 100644 --- a/app/pickle_idea2.py +++ b/app/pickle_idea2.py @@ -64,7 +64,6 @@ 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: @@ -73,6 +72,7 @@ def save_frequency_to_pickle(d, pickle_fname): f.close() +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'] if __name__ == '__main__': diff --git a/app/user_service.py b/app/user_service.py index 27323b8..24e8998 100644 --- a/app/user_service.py +++ b/app/user_service.py @@ -178,14 +178,17 @@ def user_mark_word(username): d = load_freq_history(user_freq_record) lst_history = pickle_idea2.dict2lst(d) lst = [] + lst2 = [] for word in request.form.getlist('marked'): - lst.append((word, [get_time()])) + if not word in pickle_idea2.exclusion_lst: + lst.append((word, [get_time()])) + lst2.append(word) 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(request.form.getlist('marked')))) + flash('Added %s.' % ', '.join(lst2)) return redirect(url_for('user_bp.userpage', username=username)) else: return 'Under construction' -- 2.17.1