From 0379c7e978fc5d3e6ad5ea6cadcc7360cb171924 Mon Sep 17 00:00:00 2001 From: ArrayYang <64732862+ArrayYang@users.noreply.github.com> Date: Sun, 30 May 2021 21:30:18 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8D=95=E8=AF=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户登录后可以删除自己已经认识的单词 --- .idea/.gitignore | 3 +++ .idea/englishpal.iml | 12 ++++++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ app/main.py | 10 +++++++--- app/pickle_idea2.py | 9 +++++++++ 8 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/englishpal.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/englishpal.iml b/.idea/englishpal.iml new file mode 100644 index 0000000..8b8c395 --- /dev/null +++ b/.idea/englishpal.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f6104af --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..31b95c5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/main.py b/app/main.py index 1356f12..61e02a4 100644 --- a/app/main.py +++ b/app/main.py @@ -269,7 +269,11 @@ def user_mark_word(username): else: return 'Under construction' - +@app.route("///del", methods=['GET', 'POST']) +def deleteword(username,word): + user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username) + pickle_idea2.deleteRecord(user_freq_record,word) + return redirect(url_for('userpage', username=username)) @app.route("/", methods=['GET', 'POST']) def userpage(username): @@ -345,9 +349,9 @@ def userpage(username): freq = x[1] if isinstance(d[word], list): # d[word] is a list of dates if freq > 1: - page += '

%s (%d)

\n' % (youdao_link(word), word, '; '.join(d[word]), freq) + page += '

%s(%d) 删除

\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word) else: - page += '

%s (%d)

\n' % (youdao_link(word), word, '; '.join(d[word]), freq) + page += '

%s(%d) 删除

\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word) elif isinstance(d[word], int): # d[word] is a frequency. to migrate from old format. page += '%s%d\n' % (youdao_link(word), word, freq) diff --git a/app/pickle_idea2.py b/app/pickle_idea2.py index 91a5b11..4055fc4 100644 --- a/app/pickle_idea2.py +++ b/app/pickle_idea2.py @@ -25,6 +25,15 @@ def lst2dict(lst, d): else: d[word] += dates +def deleteRecord(path,word): + with open(path, 'rb') as f: + db = pickle.load(f) + try: + db.pop(word) + except KeyError: + print("sorry") + with open(path, 'wb') as ff: + pickle.dump(db, ff) def dict2lst(d): if len(d) > 0: From 1ba4dcd45e69b8d6734317b265945ec93651987d Mon Sep 17 00:00:00 2001 From: ArrayYang <64732862+ArrayYang@users.noreply.github.com> Date: Wed, 16 Jun 2021 16:30:04 +0800 Subject: [PATCH 2/5] Create Jenkinsfile Create Jenkinsfile --- Jenkinsfile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..b8c7073 --- /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 'python3 -m pytest -v -s --html=EnglishPalTestReport.html ./app/test' + } + } + stage('DeployIt') { + steps { + echo 'Deploying (TBD)' + } + } + } +} From c3219aef1fc82de15ca82f66040679b48c6f1cfd Mon Sep 17 00:00:00 2001 From: ArrayYang <64732862+ArrayYang@users.noreply.github.com> Date: Wed, 16 Jun 2021 16:31:05 +0800 Subject: [PATCH 3/5] Create Dockerfile Create Dockerfile --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..86f0b25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.6 +COPY ./app /app From 515128caaba2e5dde9e2ac78238f706dfc4571b7 Mon Sep 17 00:00:00 2001 From: mmmmmkj <73334375+mmmmmkj@users.noreply.github.com> Date: Wed, 23 Jun 2021 00:33:19 +0800 Subject: [PATCH 4/5] upload the test code of the function called delete --- app/test/test_delete_word.py | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 app/test/test_delete_word.py diff --git a/app/test/test_delete_word.py b/app/test/test_delete_word.py new file mode 100644 index 0000000..ca08446 --- /dev/null +++ b/app/test/test_delete_word.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Run the docker image using the following command: +# docker run -d -p 4444:4444 selenium/standalone-chrome +from selenium import webdriver +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities + +import random, time +import string + +# 调用本地chromedriver +# driver = webdriver.Chrome(executable_path="D:\ChromeDriver\chromedriver.exe") +# driver.get("http://127.0.0.1:5000/") +driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME) +driver.implicitly_wait(10) +# driver.maximize_window() +# HOME_PAGE = "http://127.0.0.1:5000/" + + +HOME_PAGE = 'http://121.4.94.30:91/' + + +def test_delete_word(): + try: + driver.get(HOME_PAGE) + assert 'English Pal -' in driver.page_source + # login + elem = driver.find_element_by_link_text('登录') + elem.click() + + uname = 'lanhui' + password = '123456' + elem = driver.find_element_by_name('username') + elem.send_keys(uname) + + elem = driver.find_element_by_name('password') + elem.send_keys(password) + + elem = driver.find_element_by_xpath('//form[1]/p[3]/input[1]') # 找到登录按钮 + elem.click() + + assert 'EnglishPal Study Room for ' + uname in driver.title + + # delete + elems = driver.find_element_by_class_name('new-word') + # 移动到元素elems对象的“顶端”与当前窗口的“顶部”对齐 + driver.execute_script("arguments[0].scrollIntoView();", elems) + driver.save_screenshot('test_delete_pic1.png') + current_2 = elems.text + elem = driver.find_element_by_link_text("删除") + elem.click() + elems = driver.find_element_by_class_name('new-word') + driver.execute_script("arguments[0].scrollIntoView();", elems) + driver.save_screenshot('test_delete_pic2.png') + now_2 = elems.text + + assert current_2 != now_2 + + finally: + driver.quit() + +# test_delete_word() From ad52e5a90b2fb2a274bbe823666d4e5a3b35b45f Mon Sep 17 00:00:00 2001 From: mmmmmkj <73334375+mmmmmkj@users.noreply.github.com> Date: Wed, 23 Jun 2021 00:36:34 +0800 Subject: [PATCH 5/5] change the password --- app/test/test_delete_word.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/test_delete_word.py b/app/test/test_delete_word.py index ca08446..f42362e 100644 --- a/app/test/test_delete_word.py +++ b/app/test/test_delete_word.py @@ -28,7 +28,7 @@ def test_delete_word(): elem.click() uname = 'lanhui' - password = '123456' + password = 'l0ve1t' elem = driver.find_element_by_name('username') elem.send_keys(uname)