1
0
Fork 0

Compare commits

..

No commits in common. "a08c25a78b8f1274ce465db3dd6883f1fcac5756" and "d8af2a7e54829c92577874b77d2e8a647b8e35c3" have entirely different histories.

3 changed files with 9 additions and 23 deletions

View File

@ -64,9 +64,10 @@ 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.isnumeric() and not len(k) < 2:
if not k in exclusion_lst and 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()

View File

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

View File

@ -178,27 +178,14 @@ def user_mark_word(username):
d = load_freq_history(user_freq_record)
lst_history = pickle_idea2.dict2lst(d)
lst = []
# 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))) # 显示添加的单词
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.')
else:
flash('No new words were added.') # 没有单词被添加
pickle_idea2.save_frequency_to_pickle(d, user_freq_record)
flash('Added %s.' % (', '.join(request.form.getlist('marked'))))
return redirect(url_for('user_bp.userpage', username=username))
else:
return 'Under construction'