From dc37f5f22948c503f3e0a2bc666e2a0da6430e6b Mon Sep 17 00:00:00 2001 From: poincareS Date: Fri, 26 May 2023 17:29:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=9B=B4=E4=BE=BF=E5=88=A9?= =?UTF-8?q?=E7=9A=84=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E5=8D=95=E8=AF=8D?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BB=A5json?= =?UTF-8?q?=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//') # set route for show page 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) +