和新的master分支合并

pull/1/head
张小飞 2021-06-09 21:39:13 +08:00
commit a9b2bc6fee
8 changed files with 53 additions and 34 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ app/static/img/
app/static/frequency/frequency_*.pickle
app/static/frequency/frequency.p
app/static/wordfreqapp.db
app/static/donate-the-author.jpg
app/static/donate-the-author-hidden.jpg

View File

@ -1,2 +1,3 @@
FROM tiangolo/uwsgi-nginx-flask:python3.6
ADD ./app /app
COPY ./app /app

22
Jenkinsfile vendored
View File

@ -2,26 +2,18 @@ pipeline {
agent any
stages {
stage('pull code') {
steps {
echo 'pull code'
checkout([$class: 'GitSCM', branches: [[name: '*/SPM-Spring2021-2599-张小飞201831990641']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '15b0474b-b8eb-4574-9506-464f19a2b33e', url: 'https://github.com/lanlab-org/EnglishPal.git']]])
}
}
stage('MakeDatabasefile') {
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 englishpalzhangxf .'
sh 'sudo docker build -t englishpal .'
sh 'sudo docker stop $(docker ps -aq)'
sh 'sudo docker run -d -p 5000:80 -v /var/lib/jenkins/workspace/EnglishPal_Pipeline_master/app/static/frequency:/app/static/frequency -t englishpalzhangxf'
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') {
@ -30,9 +22,13 @@ stage('MakeDatabasefile') {
sh 'sudo docker run -d -p 4444:4444 selenium/standalone-chrome'
sh 'pip3 install pytest -U -q'
sh 'pip3 install selenium -U -q'
sh 'python3 -m pytest -v -s ./app/test'
sh 'pytest -v -s --html=EnglishPalTestReport.html ./app/test'
}
}
stage('DeployIt') {
steps {
echo 'Deploying (TBD)'
}
}
}
}

6
README.md Normal file
View File

@ -0,0 +1,6 @@
在生词簿每个单词后面,加上两个按钮,熟悉与不熟悉:
1.如果点熟悉就将生词簿中该单词后面记录的添加次数减一直至减为0就将该单词从生词簿中移除。
2.如果点不熟悉,就将生词簿中该单词后面记录的添加次数加一。
- 朱文绮

View File

@ -270,6 +270,17 @@ def user_mark_word(username):
return 'Under construction'
@app.route("/<username>/<word>/unfamiliar", methods=['GET', 'POST'])
def unfamiliar(username,word):
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
pickle_idea.unfamiliar(user_freq_record,word)
return redirect(url_for('userpage', username=username))
@app.route("/<username>/<word>/familiar", methods=['GET', 'POST'])
def familiar(username,word):
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
pickle_idea.familiar(user_freq_record,word)
return redirect(url_for('userpage', username=username))
@app.route("/<username>", methods=['GET', 'POST'])
def userpage(username):
@ -345,13 +356,11 @@ def userpage(username):
freq = x[1]
if isinstance(d[word], list): # d[word] is a list of dates
if freq > 1:
page += '<p class="new-word"> <a href="%s">%s</a> (<a title="%s">%d</a>) </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq)
page += '<p class="new-word"> <a href="%s">%s</a>(<a title="%s">%d</a>) <a href="%s/%s/familiar">熟悉</a> <a href="%s/%s/unfamiliar">不熟悉</a> </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word)
else:
page += '<p class="new-word"> <a href="%s">%s</a> <font color="white">(<a title="%s">%d</a>)</font> </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq)
page += '<p class="new-word"> <a href="%s">%s</a>(<a title="%s">%d</a>) <a href="%s/%s/familiar">熟悉</a> <a href="%s/%s/unfamiliar">不熟悉</a> </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word)
elif isinstance(d[word], int): # d[word] is a frequency. to migrate from old format.
page += '<a href="%s">%s</a>%d\n' % (youdao_link(word), word, freq)
return page
### Sign-up, login, logout ###

View File

@ -7,6 +7,7 @@
# Task: incorporate the functions into wordfreqCMD.py such that it will also show cumulative frequency.
import pickle
from datetime import datetime
def lst2dict(lst, d):
@ -53,7 +54,22 @@ def save_frequency_to_pickle(d, pickle_fname):
pickle.dump(d2, f)
f.close()
def unfamiliar(path,word):
f = open(path,"rb")
dic = pickle.load(f)
dic[word] += [datetime.now().strftime('%Y%m%d%H%M')]
fp = open(path,"wb")
pickle.dump(dic,fp)
def familiar(path,word):
f = open(path,"rb")
dic = pickle.load(f)
if len(dic[word])>1:
del dic[word][0]
else:
dic.pop(word)
fp = open(path,"wb")
pickle.dump(dic,fp)
if __name__ == '__main__':

View File

@ -67,15 +67,5 @@ def test_add_word_and_essay_does_not_change():
index = current_essay_content.find('for you.')
assert current_essay_content[index:] == essay_content[index:]
# click the Next button. Now the essay should change.
elem = driver.find_element_by_link_text('下一篇') # 找到get所有词频按钮
elem.click()
# compare again
driver.save_screenshot('./app/test/test_add_word_and_essay_does_not_change_pic2.png')
elem = driver.find_element_by_id('text-content')
next_essay_content = elem.text
assert current_essay_content[index:] != next_essay_content[index:]
finally:
driver.quit()

BIN
效果演示.mp4 Normal file

Binary file not shown.