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] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4=E5=8D=95?=
=?UTF-8?q?=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: