forked from mrlan/EnglishPal
				
			提供更便利的获取用户单词表的方法,以json数据格式范围
1、注册了一个新的蓝图路径以供功能实现 2、wordCMD中完成功能的代码代码实现SPM2023S-QianJunQi
							parent
							
								
									43c719b6b2
								
							
						
					
					
						commit
						e9ec65e7a5
					
				|  | @ -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 | ||||||
|  |  | ||||||
|  | @ -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) | ||||||
|  | 
 | ||||||
		Loading…
	
		Reference in New Issue