From d7b40ee699bdd1d0a2a561891ff30ad3cdba532f Mon Sep 17 00:00:00 2001 From: Blueotter Date: Sat, 18 Jun 2022 16:17:08 +0800 Subject: [PATCH] add wordCMD.py --- app/main.py | 2 ++ app/wordCMD.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 app/wordCMD.py diff --git a/app/main.py b/app/main.py index d903bf4..31b0e68 100644 --- a/app/main.py +++ b/app/main.py @@ -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 diff --git a/app/wordCMD.py b/app/wordCMD.py new file mode 100644 index 0000000..f5cfdd6 --- /dev/null +++ b/app/wordCMD.py @@ -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 = '' + word + '' + return result + + +@show_bp.route('/show//') +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 = '

' + f"Here are {name}'s words:" + '

' + record += '' + record += '' + record += '' + record += '' + # record += '' + for r in rq.format_results().split('\n\n'): + record += '%s' % (make_html_paragraph(r)) + # record += '' + record += '
WORDS
' + return record+'\n'