From e9ec65e7a5f77e9143ab2a2f1b1281ebc3b564d3 Mon Sep 17 00:00:00 2001
From: poincareS <poincare.s@qq.com>
Date: Fri, 26 May 2023 17:29:59 +0800
Subject: [PATCH 1/5] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=9B=B4=E4=BE=BF?=
 =?UTF-8?q?=E5=88=A9=E7=9A=84=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E5=8D=95?=
 =?UTF-8?q?=E8=AF=8D=E8=A1=A8=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BB=A5?=
 =?UTF-8?q?json=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F=E8=8C=83=E5=9B=B4=201?=
 =?UTF-8?q?=E3=80=81=E6=B3=A8=E5=86=8C=E4=BA=86=E4=B8=80=E4=B8=AA=E6=96=B0?=
 =?UTF-8?q?=E7=9A=84=E8=93=9D=E5=9B=BE=E8=B7=AF=E5=BE=84=E4=BB=A5=E4=BE=9B?=
 =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0=202=E3=80=81wordCMD?=
 =?UTF-8?q?=E4=B8=AD=E5=AE=8C=E6=88=90=E5=8A=9F=E8=83=BD=E7=9A=84=E4=BB=A3?=
 =?UTF-8?q?=E7=A0=81=E4=BB=A3=E7=A0=81=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/main.py    |  2 ++
 app/wordCMD.py | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 app/wordCMD.py

diff --git a/app/main.py b/app/main.py
index e311bb0..409ddf1 100644
--- a/app/main.py
+++ b/app/main.py
@@ -12,12 +12,14 @@ from Article import *
 import Yaml
 from user_service import userService
 from account_service import accountService
+from wordCMD import show_bp
 app = Flask(__name__)
 app.secret_key = 'lunch.time!'
 
 # 将蓝图注册到Lab app
 app.register_blueprint(userService)
 app.register_blueprint(accountService)
+app.register_blueprint(show_bp)
 
 path_prefix = '/var/www/wordfreq/wordfreq/'
 path_prefix = './'  # comment this line in deployment
diff --git a/app/wordCMD.py b/app/wordCMD.py
new file mode 100644
index 0000000..641bc18
--- /dev/null
+++ b/app/wordCMD.py
@@ -0,0 +1,37 @@
+from flask import Flask, request, Blueprint, render_template, json, jsonify
+from UseSqlite import InsertQuery, RecordQuery
+import pickle
+import difficulty
+import pickle_idea2
+from Article import load_freq_history
+from app import pickle_idea
+from app.wordfreqCMD import sort_in_descending_order
+
+path_prefix = '/var/www/wordfreq/wordfreq/'
+path_prefix = '../'  # comment this line in deployment
+
+TKTK = 'token' # set token
+
+show_bp = Blueprint(
+    'site',
+    __name__,
+)
+
+
+@show_bp.route('/show/<name>/')  # set route for show page <name> means the var name to search
+def show(name):
+    token = request.args.get("token")
+    # when token is wrong
+    if token != TKTK:
+        return "token is wrong, please try again"
+    user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (name)
+    d = load_freq_history(user_freq_record)
+    freqlst = sort_in_descending_order(pickle_idea.dict2lst(d))
+    print(freqlst)
+    words_freq=[] # 存储单词表的数组,格式为 单词-词频
+    for i in range(len(freqlst)):
+        words_freq.append(str(freqlst[i][0])+"-"+str(len(freqlst[i][1])))
+    t={}
+    t[name]=words_freq
+    return jsonify(t)
+

From dc37f5f22948c503f3e0a2bc666e2a0da6430e6b Mon Sep 17 00:00:00 2001
From: poincareS <poincare.s@qq.com>
Date: Fri, 26 May 2023 17:29:59 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=9B=B4=E4=BE=BF?=
 =?UTF-8?q?=E5=88=A9=E7=9A=84=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E5=8D=95?=
 =?UTF-8?q?=E8=AF=8D=E8=A1=A8=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BB=A5?=
 =?UTF-8?q?json=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F=E8=8C=83=E5=9B=B4=201?=
 =?UTF-8?q?=E3=80=81=E6=B3=A8=E5=86=8C=E4=BA=86=E4=B8=80=E4=B8=AA=E6=96=B0?=
 =?UTF-8?q?=E7=9A=84=E8=93=9D=E5=9B=BE=E8=B7=AF=E5=BE=84=E4=BB=A5=E4=BE=9B?=
 =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0=202=E3=80=81wordCMD?=
 =?UTF-8?q?=E4=B8=AD=E5=AE=8C=E6=88=90=E5=8A=9F=E8=83=BD=E7=9A=84=E4=BB=A3?=
 =?UTF-8?q?=E7=A0=81=E4=BB=A3=E7=A0=81=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/main.py    |  2 ++
 app/wordCMD.py | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 app/wordCMD.py

diff --git a/app/main.py b/app/main.py
index e311bb0..409ddf1 100644
--- a/app/main.py
+++ b/app/main.py
@@ -12,12 +12,14 @@ from Article import *
 import Yaml
 from user_service import userService
 from account_service import accountService
+from wordCMD import show_bp
 app = Flask(__name__)
 app.secret_key = 'lunch.time!'
 
 # 将蓝图注册到Lab app
 app.register_blueprint(userService)
 app.register_blueprint(accountService)
+app.register_blueprint(show_bp)
 
 path_prefix = '/var/www/wordfreq/wordfreq/'
 path_prefix = './'  # comment this line in deployment
diff --git a/app/wordCMD.py b/app/wordCMD.py
new file mode 100644
index 0000000..641bc18
--- /dev/null
+++ b/app/wordCMD.py
@@ -0,0 +1,37 @@
+from flask import Flask, request, Blueprint, render_template, json, jsonify
+from UseSqlite import InsertQuery, RecordQuery
+import pickle
+import difficulty
+import pickle_idea2
+from Article import load_freq_history
+from app import pickle_idea
+from app.wordfreqCMD import sort_in_descending_order
+
+path_prefix = '/var/www/wordfreq/wordfreq/'
+path_prefix = '../'  # comment this line in deployment
+
+TKTK = 'token' # set token
+
+show_bp = Blueprint(
+    'site',
+    __name__,
+)
+
+
+@show_bp.route('/show/<name>/')  # set route for show page <name> means the var name to search
+def show(name):
+    token = request.args.get("token")
+    # when token is wrong
+    if token != TKTK:
+        return "token is wrong, please try again"
+    user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (name)
+    d = load_freq_history(user_freq_record)
+    freqlst = sort_in_descending_order(pickle_idea.dict2lst(d))
+    print(freqlst)
+    words_freq=[] # 存储单词表的数组,格式为 单词-词频
+    for i in range(len(freqlst)):
+        words_freq.append(str(freqlst[i][0])+"-"+str(len(freqlst[i][1])))
+    t={}
+    t[name]=words_freq
+    return jsonify(t)
+

From 2fb300380864b490183f6f02ba7efaaf5067cc0e Mon Sep 17 00:00:00 2001
From: poincareS <poincare.s@qq.com>
Date: Sun, 4 Jun 2023 10:41:24 +0800
Subject: [PATCH 3/5] =?UTF-8?q?fix:=202023.6.1=201.=20=E5=88=A0=E5=8E=BB?=
 =?UTF-8?q?=E4=BA=86wordCMD.py=E4=B8=AD=EF=BC=9A=20from=20flask=20import?=
 =?UTF-8?q?=20....,Blueprint,....=20=E6=94=B9=E4=B8=BA=EF=BC=9A=20from=20f?=
 =?UTF-8?q?lask=20import=20*=202.=20=E4=BF=AE=E6=94=B9=E4=BA=86=E4=BB=A3?=
 =?UTF-8?q?=E7=A0=81=E7=9A=84=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=8C=85=E6=8B=AC?=
 =?UTF-8?q?=EF=BC=9A=E7=AD=89=E5=8F=B7=E4=B8=A4=E8=BE=B9=E7=9A=84=E7=A9=BA?=
 =?UTF-8?q?=E6=A0=BC=E3=80=81=E5=8A=A0=E5=8F=B7=E4=B8=A4=E8=BE=B9=E7=9A=84?=
 =?UTF-8?q?=E7=A9=BA=E6=A0=BC=203.=20=E6=9B=B4=E6=96=B0=E4=BA=86=E8=AE=BF?=
 =?UTF-8?q?=E9=97=AE=E7=94=A8=E6=88=B7=E5=8D=95=E8=AF=8D=E7=9A=84token?=
 =?UTF-8?q?=E9=AA=8C=E8=AF=81=203.1=20=E4=BD=BF=E7=94=A8Authorization?=
 =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AE=B5=E5=80=BC=EF=BC=88Bearer=20xxx)?=
 =?UTF-8?q?=E9=AA=8C=E8=AF=81token=203.2=20=E5=8F=96=E6=B6=88=E4=BA=86?=
 =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=AE=BF=E9=97=AE=E7=94=A8=E6=88=B7=E5=8D=95?=
 =?UTF-8?q?=E8=AF=8D=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8F=AA=E8=83=BD?=
 =?UTF-8?q?=E5=9C=A8=E7=BB=88=E7=AB=AF=E5=91=BD=E4=BB=A4=E8=A1=8C=E4=B8=AD?=
 =?UTF-8?q?=E8=BE=93=E5=85=A5:=20"curl=20-H=20"Authorization:=20Bearer=20?=
 =?UTF-8?q?=E5=AF=86=E9=92=A5"=20http://127.0.0.1:5000/show/=E7=94=A8?=
 =?UTF-8?q?=E6=88=B7=E5=90=8D/"=E8=8E=B7=E5=8F=96=E5=8D=95=E8=AF=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/wordCMD.py | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/app/wordCMD.py b/app/wordCMD.py
index 641bc18..dd579da 100644
--- a/app/wordCMD.py
+++ b/app/wordCMD.py
@@ -1,37 +1,39 @@
-from flask import Flask, request, Blueprint, render_template, json, jsonify
-from UseSqlite import InsertQuery, RecordQuery
-import pickle
-import difficulty
-import pickle_idea2
+from flask import *
+from flask_httpauth import HTTPTokenAuth
 from Article import load_freq_history
-from app import pickle_idea
-from app.wordfreqCMD import sort_in_descending_order
+from wordfreqCMD import sort_in_descending_order
+import pickle_idea
+
+auth = HTTPTokenAuth(scheme='Bearer')
 
 path_prefix = '/var/www/wordfreq/wordfreq/'
-path_prefix = '../'  # comment this line in deployment
-
-TKTK = 'token' # set token
+path_prefix = './'  # comment this line in deployment
 
 show_bp = Blueprint(
     'site',
     __name__,
 )
 
+tokens = {
+    "token": "token"
+}
+
+
+@auth.verify_token
+def verify_token(token):
+    if token in tokens:
+        return tokens[token]
+
 
 @show_bp.route('/show/<name>/')  # set route for show page <name> means the var name to search
+@auth.login_required
 def show(name):
-    token = request.args.get("token")
-    # when token is wrong
-    if token != TKTK:
-        return "token is wrong, please try again"
     user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (name)
     d = load_freq_history(user_freq_record)
     freqlst = sort_in_descending_order(pickle_idea.dict2lst(d))
-    print(freqlst)
-    words_freq=[] # 存储单词表的数组,格式为 单词-词频
+    words_freq = []  # 存储单词表的数组,格式为 单词-词频
     for i in range(len(freqlst)):
-        words_freq.append(str(freqlst[i][0])+"-"+str(len(freqlst[i][1])))
-    t={}
-    t[name]=words_freq
+        words_freq.append(str(freqlst[i][0]) + "-" + str(len(freqlst[i][1])))
+    t = {}
+    t[name] = words_freq
     return jsonify(t)
-

From ceb5f14ee97d288c069921862ce59f435662be28 Mon Sep 17 00:00:00 2001
From: Lan Hui <1348141770@qq.com>
Date: Sat, 31 Aug 2024 07:35:50 +0800
Subject: [PATCH 4/5] Simplify wordCMD.py and rename it to api_service.py

---
 app/api_service.py | 31 +++++++++++++++++++++++++++++++
 app/main.py        |  3 ++-
 app/wordCMD.py     | 39 ---------------------------------------
 3 files changed, 33 insertions(+), 40 deletions(-)
 create mode 100644 app/api_service.py
 delete mode 100644 app/wordCMD.py

diff --git a/app/api_service.py b/app/api_service.py
new file mode 100644
index 0000000..034a46d
--- /dev/null
+++ b/app/api_service.py
@@ -0,0 +1,31 @@
+from flask import *
+from flask_httpauth import HTTPTokenAuth
+from Article import load_freq_history
+
+path_prefix = '/var/www/wordfreq/wordfreq/'
+path_prefix = './'  # comment this line in deployment
+
+show_bp = Blueprint('site',__name__)
+
+auth = HTTPTokenAuth(scheme='Bearer')
+
+tokens = {
+    "token": "token",
+    "secret-token": "lanhui"  # token, username
+}
+
+
+@auth.verify_token
+def verify_token(token):
+    if token in tokens:
+        return tokens[token]
+
+
+@show_bp.route('/api/mywords')  # HTTPie usage: http -A bearer -a secret-token  http://127.0.0.1:5000/api/mywords
+@auth.login_required
+def show():
+    username = auth.current_user()
+    word_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
+    d = load_freq_history(word_freq_record)
+    return jsonify(d)
+
diff --git a/app/main.py b/app/main.py
index 19e82f2..eeb4960 100644
--- a/app/main.py
+++ b/app/main.py
@@ -10,9 +10,10 @@ import Yaml
 from user_service import userService
 from account_service import accountService
 from admin_service import adminService, ADMIN_NAME
+from api_service import show_bp
 import os
 from translate import *
-from wordCMD import show_bp
+
 
 app = Flask(__name__)
 app.secret_key = os.urandom(32)
diff --git a/app/wordCMD.py b/app/wordCMD.py
deleted file mode 100644
index dd579da..0000000
--- a/app/wordCMD.py
+++ /dev/null
@@ -1,39 +0,0 @@
-from flask import *
-from flask_httpauth import HTTPTokenAuth
-from Article import load_freq_history
-from wordfreqCMD import sort_in_descending_order
-import pickle_idea
-
-auth = HTTPTokenAuth(scheme='Bearer')
-
-path_prefix = '/var/www/wordfreq/wordfreq/'
-path_prefix = './'  # comment this line in deployment
-
-show_bp = Blueprint(
-    'site',
-    __name__,
-)
-
-tokens = {
-    "token": "token"
-}
-
-
-@auth.verify_token
-def verify_token(token):
-    if token in tokens:
-        return tokens[token]
-
-
-@show_bp.route('/show/<name>/')  # set route for show page <name> means the var name to search
-@auth.login_required
-def show(name):
-    user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (name)
-    d = load_freq_history(user_freq_record)
-    freqlst = sort_in_descending_order(pickle_idea.dict2lst(d))
-    words_freq = []  # 存储单词表的数组,格式为 单词-词频
-    for i in range(len(freqlst)):
-        words_freq.append(str(freqlst[i][0]) + "-" + str(len(freqlst[i][1])))
-    t = {}
-    t[name] = words_freq
-    return jsonify(t)

From 621ac24991a68ffece9d49044034794b241a241a Mon Sep 17 00:00:00 2001
From: Lan Hui <1348141770@qq.com>
Date: Sat, 31 Aug 2024 07:38:30 +0800
Subject: [PATCH 5/5] Give the blueprint a better name: apiService

---
 app/api_service.py | 4 ++--
 app/main.py        | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/app/api_service.py b/app/api_service.py
index 034a46d..fd88681 100644
--- a/app/api_service.py
+++ b/app/api_service.py
@@ -5,7 +5,7 @@ from Article import load_freq_history
 path_prefix = '/var/www/wordfreq/wordfreq/'
 path_prefix = './'  # comment this line in deployment
 
-show_bp = Blueprint('site',__name__)
+apiService = Blueprint('site',__name__)
 
 auth = HTTPTokenAuth(scheme='Bearer')
 
@@ -21,7 +21,7 @@ def verify_token(token):
         return tokens[token]
 
 
-@show_bp.route('/api/mywords')  # HTTPie usage: http -A bearer -a secret-token  http://127.0.0.1:5000/api/mywords
+@apiService.route('/api/mywords')  # HTTPie usage: http -A bearer -a secret-token  http://127.0.0.1:5000/api/mywords
 @auth.login_required
 def show():
     username = auth.current_user()
diff --git a/app/main.py b/app/main.py
index eeb4960..4af4456 100644
--- a/app/main.py
+++ b/app/main.py
@@ -10,7 +10,7 @@ import Yaml
 from user_service import userService
 from account_service import accountService
 from admin_service import adminService, ADMIN_NAME
-from api_service import show_bp
+from api_service import apiService
 import os
 from translate import *
 
@@ -22,7 +22,7 @@ app.secret_key = os.urandom(32)
 app.register_blueprint(userService)
 app.register_blueprint(accountService)
 app.register_blueprint(adminService)
-app.register_blueprint(show_bp)
+app.register_blueprint(apiService)
 
 path_prefix = '/var/www/wordfreq/wordfreq/'
 path_prefix = './'  # comment this line in deployment