Compare commits
	
		
			1 Commits 
		
	
	
		
			master
			...
			Bug473-Buy
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								 | 
						8890e4250a | 
| 
						 | 
					@ -0,0 +1,44 @@
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from flask import Blueprint, session, jsonify
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import pickle_idea2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					path_prefix = '/var/www/wordfreq/wordfreq/'
 | 
				
			||||||
 | 
					path_prefix = './'  # comment this line in deployment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 创建api蓝图
 | 
				
			||||||
 | 
					api_blue = Blueprint('api', __name__, url_prefix='/api')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def helper(res, result):
 | 
				
			||||||
 | 
					    for item in res:
 | 
				
			||||||
 | 
					        if type(res[str(item)]) == 'dict':
 | 
				
			||||||
 | 
					            helper(res[str(item)], result)
 | 
				
			||||||
 | 
					        if type(res[str(item)]) == 'list':
 | 
				
			||||||
 | 
					            for i in range(len(res[str(item)])):
 | 
				
			||||||
 | 
					                helper(res[str(item)][i], result)
 | 
				
			||||||
 | 
					        result.append(str(item))
 | 
				
			||||||
 | 
					    return result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@api_blue.route('/json/<username>', methods=['GET'])
 | 
				
			||||||
 | 
					def api_bp(username):
 | 
				
			||||||
 | 
					    # 获取session里的用户名,必须携带token
 | 
				
			||||||
 | 
					    token = session.get("token")
 | 
				
			||||||
 | 
					    if token == "70620F32A9DC965FCCF0447B674AA161":
 | 
				
			||||||
 | 
					        result = []
 | 
				
			||||||
 | 
					        user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
 | 
				
			||||||
 | 
					        s = pickle_idea2.load_record(user_freq_record)
 | 
				
			||||||
 | 
					        wordlist = helper(s, result)
 | 
				
			||||||
 | 
					        print(json.dumps(s))
 | 
				
			||||||
 | 
					        results = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for word in wordlist:
 | 
				
			||||||
 | 
					            results[word] = len(s[word])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return jsonify(results)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        print("无效的token")
 | 
				
			||||||
 | 
					        return jsonify({"error": "无效的token"})
 | 
				
			||||||
| 
						 | 
					@ -11,14 +11,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 admin_service import adminService, ADMIN_NAME
 | 
					from api_bp import api_blue
 | 
				
			||||||
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(adminService)
 | 
					app.register_blueprint(api_blue)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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
 | 
				
			||||||
| 
						 | 
					@ -98,7 +98,7 @@ def mainpage():
 | 
				
			||||||
        d_len = len(d)
 | 
					        d_len = len(d)
 | 
				
			||||||
        lst = sort_in_descending_order(pickle_idea.dict2lst(d))
 | 
					        lst = sort_in_descending_order(pickle_idea.dict2lst(d))
 | 
				
			||||||
        return render_template('mainpage_get.html', 
 | 
					        return render_template('mainpage_get.html', 
 | 
				
			||||||
                               admin_name=ADMIN_NAME,
 | 
					                               #admin_name=ADMIN_NAME,
 | 
				
			||||||
                               random_ads=random_ads,
 | 
					                               random_ads=random_ads,
 | 
				
			||||||
                               d_len=d_len,
 | 
					                               d_len=d_len,
 | 
				
			||||||
                               lst=lst,
 | 
					                               lst=lst,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue