def get_expiry_date(username): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') rq.instructions("SELECT expiry_date FROM user WHERE name='%s'" % (username)) rq.do() result = rq.format_results() return result.strip()
def verify_user(username, password): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') rq.instructions("SELECT * FROM user WHERE name='%s' AND password='******'" % (username, password)) rq.do() result = rq.format_results() return result.strip() != ''
def get_expiry_date(username): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') rq.instructions("SELECT expiry_date FROM user WHERE name='%s'" % (username)) rq.do() result = rq.get_results() if len(result) > 0: return result[0]['expiry_date'] else: return '20191024'
def get_today_article(user_word_list, articleID): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') if articleID == None: rq.instructions("SELECT * FROM article") else: rq.instructions('SELECT * FROM article WHERE article_id=%d' % (articleID)) rq.do() result = rq.get_results() # Choose article according to reader's level d1 = load_freq_history(path_prefix + 'static/frequency/frequency.p') d2 = load_freq_history(path_prefix + 'static/words_and_tests.p') d3 = get_difficulty_level(d1, d2) d = {} 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 d = random.choice(result) text_level = text_difficulty_level(d['text'], d3) if articleID == None: for reading in result: text_level = text_difficulty_level(reading['text'], d3) #print('TEXT_LEVEL %4.2f' % (text_level)) if within_range(text_level, user_level, 0.5): d = reading break s = '<p><i>According to your word list, your level is <b>%4.2f</b> and we have chosen an article with a difficulty level of <b>%4.2f</b> for you.</i></p>' % ( user_level, text_level) s += '<p><b>%s</b></p>' % (d['date']) s += '<p><font size=+2>%s</font></p>' % (d['text']) s += '<p><i>%s</i></p>' % (d['source']) s += '<p><b>%s</b></p>' % (get_question_part(d['question'])) s = s.replace('\n', '<br/>') s += '%s' % (get_answer_part(d['question'])) session['articleID'] = d['article_id'] return s
def check_username_availability(username): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') rq.instructions("SELECT * FROM user WHERE name='%s'" % (username)) rq.do() result = rq.format_results() return result.strip() == ''