diff --git a/.gitignore b/.gitignore index 7a8be9f..055a2d5 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,5 @@ app/static/img/ app/static/frequency/frequency_*.pickle app/static/frequency/frequency.p app/static/wordfreqapp.db -app/static/wordfreqapp.sql app/static/donate-the-author.jpg app/static/donate-the-author-hidden.jpg diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fc16a1b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.6 +COPY ./app /app \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..434c00f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,34 @@ +pipeline { + agent any + + stages { + stage('MakeDatabasefile') { + steps { + sh 'touch ./app/static/wordfreqapp.db && rm -f ./app/static/wordfreqapp.db' + sh 'cat ./app/static/wordfreqapp.sql | sqlite3 ./app/static/wordfreqapp.db' + } + } + stage('BuildIt') { + steps { + echo 'Building..' + sh 'sudo docker build -t englishpal .' + sh 'sudo docker stop $(docker ps -aq)' + sh 'sudo docker run -d -p 91:80 -v /var/lib/jenkins/workspace/EnglishPal_Pipeline_master/app/static/frequency:/app/static/frequency -t englishpal' + } + } + stage('TestIt') { + steps { + echo 'Testing..' + sh 'sudo docker run -d -p 4444:4444 selenium/standalone-chrome' + sh 'pip3 install pytest -U -q' + sh 'pip3 install selenium -U -q' + sh 'pytest -v -s --html=EnglishPalTestReport.html ./app/test' + } + } + stage('DeployIt') { + steps { + echo 'Deploying (TBD)' + } + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..570c7f2 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +在生词簿每个单词后面,加上两个按钮,熟悉与不熟悉: +1.如果点熟悉,就将生词簿中该单词后面记录的添加次数减一,直至减为0,就将该单词从生词簿中移除。 +2.如果点不熟悉,就将生词簿中该单词后面记录的添加次数加一。 + +- 朱文绮 + diff --git a/app/main.py b/app/main.py index c862b83..6d743bb 100644 --- a/app/main.py +++ b/app/main.py @@ -20,26 +20,22 @@ app = Flask(__name__) app.secret_key = 'lunch.time!' path_prefix = '/var/www/wordfreq/wordfreq/' -path_prefix = './' # comment this line in deployment - +path_prefix = './' # comment this line in deployment def get_random_image(path): img_path = random.choice(glob.glob(os.path.join(path, '*.jpg'))) return img_path[img_path.rfind('/static'):] - def get_random_ads(): ads = random.choice(['个性化分析精准提升', '你的专有单词本', '智能捕捉阅读弱点,针对性提高你的阅读水平']) return ads + '。 试试吧!' - def load_freq_history(path): d = {} if os.path.exists(path): d = pickle_idea.load_record(path) return d - def verify_user(username, password): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') rq.instructions("SELECT * FROM user WHERE name='%s' AND password='%s'" % (username, password)) @@ -47,7 +43,6 @@ def verify_user(username, password): result = rq.get_results() return result != [] - def add_user(username, password): start_date = datetime.now().strftime('%Y%m%d') expiry_date = '20211230' @@ -55,14 +50,13 @@ def add_user(username, password): rq.instructions("INSERT INTO user Values ('%s', '%s', '%s', '%s')" % (username, password, start_date, expiry_date)) rq.do() - + 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.get_results() - return result == [] - + return result == [] def get_expiry_date(username): rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') @@ -70,24 +64,26 @@ def get_expiry_date(username): rq.do() result = rq.get_results() if len(result) > 0: - return result[0]['expiry_date'] + return result[0]['expiry_date'] else: return '20191024' + def within_range(x, y, r): - return x > y and abs(x - y) <= r + return x > y and abs(x - y) <= r def get_today_article(user_word_list, articleID): + rq = RecordQuery(path_prefix + 'static/wordfreqapp.db') - if articleID == None: + 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') @@ -95,26 +91,24 @@ def get_today_article(user_word_list, articleID): 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 + 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)) + #print('TEXT_LEVEL %4.2f' % (text_level)) if within_range(text_level, user_level, 0.5): d = reading break - - 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']) s += '%s
' % (get_question_part(d['question'])) - s = s.replace('\n', '%s
' % (get_random_ads()) page += '粘帖1篇文章 (English only)
' page += '