forked from mrlan/EnglishPal
				
			add wordCMD.py
							parent
							
								
									e48008550a
								
							
						
					
					
						commit
						d7b40ee699
					
				|  | @ -11,12 +11,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 | ||||
|  |  | |||
|  | @ -0,0 +1,42 @@ | |||
| from flask import Flask, request, Blueprint, render_template | ||||
| from UseSqlite import InsertQuery, RecordQuery | ||||
| 
 | ||||
| TKTK = 'token' | ||||
| 
 | ||||
| show_bp = Blueprint( | ||||
|     'site', | ||||
|     __name__, | ||||
| ) | ||||
| 
 | ||||
| 
 | ||||
| def make_html_paragraph(s): | ||||
|     if s.strip() == '': | ||||
|         return '' | ||||
|     lst = s.split(',') | ||||
|     word = lst[1].strip() | ||||
|     result = '<tr><td>' + word + '</td></tr>' | ||||
|     return result | ||||
| 
 | ||||
| 
 | ||||
| @show_bp.route('/show/<name>/') | ||||
| def show(name): | ||||
|     token = request.args.get("token") | ||||
| 
 | ||||
|     if token != TKTK: | ||||
|         return "token is wrong, please try again" | ||||
| 
 | ||||
|     rq = RecordQuery('./static/wordfreqapp.db') | ||||
|     rq.instructions("SELECT * FROM words where user = \'" + name + "\'") | ||||
|     rq.do() | ||||
| 
 | ||||
|     record =  '<h1>' + f"Here are {name}'s words:" + '</h1>' | ||||
|     record += '<table border= \"2\" >' | ||||
|     record += '<tr>' | ||||
|     record += '<th>WORDS</th>' | ||||
|     record += '</tr>' | ||||
|     # record += '<tr>' | ||||
|     for r in rq.format_results().split('\n\n'): | ||||
|         record += '%s' % (make_html_paragraph(r)) | ||||
|     # record += '</tr>' | ||||
|     record += '</table>' | ||||
|     return record+'\n' | ||||
		Loading…
	
		Reference in New Issue