From 2fb300380864b490183f6f02ba7efaaf5067cc0e Mon Sep 17 00:00:00 2001 From: poincareS Date: Sun, 4 Jun 2023 10:41:24 +0800 Subject: [PATCH] =?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//') # set route for show page 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) -