diff --git a/.gitignore b/.gitignore
index 055a2d5..413c71c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.idea/
venv/
app/__init__.py
app/__pycache__/
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/Dockerfile b/Dockerfile
index 555b36d..86f0b25 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,3 +1,2 @@
FROM tiangolo/uwsgi-nginx-flask:python3.6
COPY ./app /app
-
diff --git a/Jenkinsfile b/Jenkinsfile
index b005e85..434c00f 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -12,7 +12,7 @@ pipeline {
steps {
echo 'Building..'
sh 'sudo docker build -t englishpal .'
- sh 'sudo docker stop $(sudo docker ps -aq)'
+ 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'
}
}
diff --git a/app/main.py b/app/main.py
index 11edeb3..f35b65c 100644
--- a/app/main.py
+++ b/app/main.py
@@ -282,6 +282,12 @@ def familiar(username,word):
pickle_idea.familiar(user_freq_record,word)
return redirect(url_for('userpage', username=username))
+@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):
@@ -356,9 +362,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,username, word,username,word)
+ page += ' %s(%d) 熟悉 不熟悉 删除
\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word, username,word)
else:
- page += ' %s(%d) 熟悉 不熟悉
\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word)
+ page += ' %s(%d) 熟悉 不熟悉 删除
\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word, 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)
return page
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:
diff --git a/app/test/test_delete_word.py b/app/test/test_delete_word.py
new file mode 100644
index 0000000..f42362e
--- /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 = 'l0ve1t'
+ 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()