Compare commits

...

4 Commits

Author SHA1 Message Date
poincareS 0ed7657747 Merge remote-tracking branch 'origin/SPM2023S-QianJunQi' into SPM2023S-QianJunQi
# Conflicts:
#	app/wordCMD.py
2023-06-04 10:42:40 +08:00
poincareS 2fb3003808 fix: 2023.6.1
1. 删去了wordCMD.py中:
from flask import ....,Blueprint,....
改为:
from flask import *
2. 修改了代码的格式,包括:等号两边的空格、加号两边的空格
3. 更新了访问用户单词的token验证
3.1 使用Authorization的字段值(Bearer xxx)验证token
3.2 取消了路由访问用户单词的功能,只能在终端命令行中输入: "curl -H "Authorization: Bearer 密钥" http://127.0.0.1:5000/show/用户名/"获取单词
2023-06-04 10:41:24 +08:00
poincareS dc37f5f229 提供更便利的获取用户单词表的方法,以json数据格式范围
1、注册了一个新的蓝图路径以供功能实现
2、wordCMD中完成功能的代码代码实现
2023-05-26 17:34:43 +08:00
poincareS e9ec65e7a5 提供更便利的获取用户单词表的方法,以json数据格式范围
1、注册了一个新的蓝图路径以供功能实现
2、wordCMD中完成功能的代码代码实现
2023-05-26 17:29:59 +08:00
2 changed files with 41 additions and 0 deletions

View File

@ -12,12 +12,14 @@ from Article import *
import Yaml import Yaml
from user_service import userService from user_service import userService
from account_service import accountService from account_service import accountService
from wordCMD import show_bp
app = Flask(__name__) app = Flask(__name__)
app.secret_key = 'lunch.time!' app.secret_key = 'lunch.time!'
# 将蓝图注册到Lab app # 将蓝图注册到Lab app
app.register_blueprint(userService) app.register_blueprint(userService)
app.register_blueprint(accountService) app.register_blueprint(accountService)
app.register_blueprint(show_bp)
path_prefix = '/var/www/wordfreq/wordfreq/' path_prefix = '/var/www/wordfreq/wordfreq/'
path_prefix = './' # comment this line in deployment path_prefix = './' # comment this line in deployment

39
app/wordCMD.py Normal file
View File

@ -0,0 +1,39 @@
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)