diff --git a/app/main.py b/app/main.py index 634338a..3818ea6 100644 --- a/app/main.py +++ b/app/main.py @@ -81,6 +81,15 @@ def within_range(x, y, r): return x > y and abs(x - y) <= r +def get_article_title(s): + return s.split('\n')[0] + + +def get_article_body(s): + lst = s.split('\n') + lst.pop(0) # remove the first line + return '\n'.join(lst) + def get_today_article(user_word_list, articleID): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') @@ -111,12 +120,17 @@ def get_today_article(user_word_list, articleID): break s = '' % (user_level, text_level) - s += '

%s

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

%s

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

%s

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

Article added on: %s

' % (d['date']) + s += '
' + article_title = get_article_title(d['text']) + article_body = get_article_body(d['text']) + s += '

%s

' % (article_title) + s += '

%s

' % (article_body) + s += '

%s

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

%s

' % (get_question_part(d['question'])) s = s.replace('\n', '
') s += '%s' % (get_answer_part(d['question'])) + s += '
' session['articleID'] = d['article_id'] return s @@ -237,6 +251,7 @@ def mainpage(): ''' + page += '
' page += '

English Pal - Learn English smartly!

' if session.get('logged_in'): page += ' %s

\n' % (session['username'], session['username']) @@ -260,6 +275,7 @@ def mainpage(): page += '%s %d\n' % (youdao_link(x[0]), x[0], x[1]) page += ' ' + page += '
' page += '' return page @@ -341,9 +357,10 @@ def userpage(username): page += '\n' # forbid treating numbers as cell numbers in smart phones page += '' page += 'EnglishPal Study Room for %s' % (username) - page += '

English Pal for %s 登出

' % (username) + page += '
' + page += '

English Pal for %s 登出

' % (username) page += '

阅读文章并回答问题

\n' - page += '

下一篇

' % (username) + page += '

下一篇 Next Article

' % (username) page += '
%s
' % (get_today_article(user_freq_record, session['articleID'])) page += '

收集生词吧 (可以在正文中划词,也可以复制黏贴)

' page += '
' % (username) @@ -398,6 +415,7 @@ def userpage(username): elif isinstance(d[word], int): # d[word] is a frequency. to migrate from old format. page += '%s%d\n' % (youdao_link(word), word, freq) page += '' + page += '
' return page ### Sign-up, login, logout ###