处理了“注册之后跳出文章获取错误,today_article为空”的bug,但并未真正获取文章数据,只是增加了一个测试文章

Bug585-WangLulu
王露露 2025-06-06 18:38:20 +08:00
parent e97951d91f
commit 6267eea862
1 changed files with 21 additions and 9 deletions

View File

@ -84,7 +84,7 @@ def get_today_article(user_word_list, visited_articles):
text_level = 0
if visited_articles["index"] > len(visited_articles["article_ids"]) - 1: # 生成新的文章
amount_of_visited_articles = len(visited_articles["article_ids"])
amount_of_existing_articles = result.__len__()
amount_of_existing_articles = len(result)
if amount_of_visited_articles == amount_of_existing_articles: # 如果当前阅读过的文章的数量 == 存在的文章的数量,即所有的书本都阅读过了
result_of_generate_article = "had read all articles"
else:
@ -106,8 +106,20 @@ def get_today_article(user_word_list, visited_articles):
text_level = text_difficulty_level(d['text'], d3)
result_of_generate_article = "found"
today_article = None
if d:
if d is None:
# 如果没有找到合适的文章,返回一个默认的文章对象
today_article = {
"user_level": '0.0',
"text_level": '0.0',
"date": datetime.now().strftime('%Y-%m-%d'),
"article_title": "Default Article",
"article_body": "This is a default article for testing purposes.",
"source": "Default Source",
"question": "What is this article about?",
"answer": "It's a default article for testing.",
"ratio": 0.0
}
else:
oxford_words = load_oxford_words(oxford_words_path)
oxford_word_count, total_words = count_oxford_words(d['text'], oxford_words)
ratio = calculate_ratio(oxford_word_count, total_words)