处理了“注册之后跳出文章获取错误,today_article为空”的bug,但并未真正获取文章数据,只是增加了一个测试文章
parent
e97951d91f
commit
6267eea862
|
@ -53,10 +53,10 @@ def get_article_body(s):
|
|||
def get_today_article(user_word_list, visited_articles):
|
||||
if visited_articles is None:
|
||||
visited_articles = {
|
||||
"index" : 0, # 为 article_ids 的索引
|
||||
"index": 0, # 为 article_ids 的索引
|
||||
"article_ids": [] # 之前显示文章的id列表,越后越新
|
||||
}
|
||||
if visited_articles["index"] > len(visited_articles["article_ids"])-1: # 生成新的文章,因此查找所有的文章
|
||||
if visited_articles["index"] > len(visited_articles["article_ids"]) - 1: # 生成新的文章,因此查找所有的文章
|
||||
result = get_all_articles()
|
||||
else: # 生成阅读过的文章,因此查询指定 article_id 的文章
|
||||
if visited_articles["article_ids"][visited_articles["index"]] == 'null': # 可能因为直接刷新页面导致直接去查询了'null',因此当刷新的页面的时候,需要直接进行“上一篇”操作
|
||||
|
@ -82,9 +82,9 @@ def get_today_article(user_word_list, visited_articles):
|
|||
user_level = user_difficulty_level(d_user, d3) # more consideration as user's behaviour is dynamic. Time factor should be considered.
|
||||
logging.debug('* get_today_article(): done')
|
||||
text_level = 0
|
||||
if visited_articles["index"] > len(visited_articles["article_ids"])-1: # 生成新的文章
|
||||
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,11 +106,23 @@ 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)
|
||||
oxford_word_count, total_words = count_oxford_words(d['text'], oxford_words)
|
||||
ratio = calculate_ratio(oxford_word_count, total_words)
|
||||
today_article = {
|
||||
"user_level": '%4.1f' % user_level,
|
||||
"text_level": '%4.1f' % text_level,
|
||||
|
@ -120,7 +132,7 @@ def get_today_article(user_word_list, visited_articles):
|
|||
"source": d["source"],
|
||||
"question": get_question_part(d['question']),
|
||||
"answer": get_answer_part(d['question']),
|
||||
"ratio" : ratio
|
||||
"ratio": ratio
|
||||
}
|
||||
|
||||
return visited_articles, today_article, result_of_generate_article
|
||||
|
|
Loading…
Reference in New Issue