From e7fdeb6d2f21772277e07c4c0031235c56cf0276 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Wed, 12 Aug 2020 08:13:06 +0800 Subject: main.py: refactor code. --- app/main.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/main.py b/app/main.py index 38250b3..cccb46a 100644 --- a/app/main.py +++ b/app/main.py @@ -87,10 +87,11 @@ def get_today_article(user_word_list): d3 = get_difficulty_level(d1, d2) d = {} - no_match = 0 d_user = load_freq_history(user_word_list) user_level = user_difficulty_level(d_user, d3) # more consideration as user's behaviour is dynamic. Time factor should be considered. - random.shuffle(result) # shuffle list + random.shuffle(result) # shuffle list + d = random.choice(result) + text_level = text_difficulty_level(d['text'], d3) for reading in result: text_level = text_difficulty_level(reading['text'], d3) #print('TEXT_LEVEL %4.2f' % (text_level)) @@ -98,12 +99,7 @@ def get_today_article(user_word_list): d = reading break - if len(d) == 0: - no_match = 1 - d = random.choice(result) - text_level = text_difficulty_level(d['text'], d3) - - s = '

According to your word list, your level is %4.2f and we have chosen an article with a difficulty level of %4.2f for you.

' % (user_level, text_level) + s = '

According to your word list, your level is %4.2f and we have chosen an article with a difficulty level of %4.2f for you.

' % (user_level, text_level) s += '

%s

' % (d['date']) s += '

%s

' % (d['text']) s += '

%s

' % (d['source']) -- cgit v1.2.1