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) -