From fa3012920e67bbf6e49ee20bc3a7985a6852f7f3 Mon Sep 17 00:00:00 2001 From: salma Date: Sun, 21 May 2023 23:59:36 +0800 Subject: [PATCH 1/2] improved show() function, and added show.html template --- app/templates/show.html | 9 +++++++++ app/wordCMD.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 app/templates/show.html create mode 100644 app/wordCMD.py diff --git a/app/templates/show.html b/app/templates/show.html new file mode 100644 index 0000000..50b51e0 --- /dev/null +++ b/app/templates/show.html @@ -0,0 +1,9 @@ +

Here are {{ name }}'s words:

+ + + + + {% for word in results %} + + {% endfor %} +
WORDS
{{ word }}
\ No newline at end of file diff --git a/app/wordCMD.py b/app/wordCMD.py new file mode 100644 index 0000000..412e600 --- /dev/null +++ b/app/wordCMD.py @@ -0,0 +1,33 @@ +from flask import Flask, request, Blueprint, render_template +from UseSqlite import InsertQuery, RecordQuery + +TKTK = 'token' # set token + +show_bp = Blueprint( + 'site', + __name__, +) + +# The following function is replaced by the template show.html. +# And can be safely deleted. +# def make_html_paragraph(s): # build the word's table +# if s.strip() == '': +# return '' +# lst = s.split(',') +# word = lst[1].strip() +# result = '' + word + '' +# return result + +@show_bp.route('/show//') # set route for show page 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" + + rq = RecordQuery('./static/wordfreqapp.db') + # search the user's words in db + rq.instructions_with_parameters("SELECT * FROM words WHERE user = ?", (name,)) + rq.do_with_parameters() + results = [row.split(",")[1].strip() for row in rq.format_results().split("\n\n")] + return render_template("show.html", name=name, results=results) -- 2.17.1 From 1ce6dcf41b3c7a719455b6297868f7fc22adc162 Mon Sep 17 00:00:00 2001 From: salma Date: Mon, 5 Jun 2023 11:28:51 +0800 Subject: [PATCH 2/2] synced with Alpha-snapshot20230525 --- app/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/main.py b/app/main.py index 4e3f829..aeaa5c1 100644 --- a/app/main.py +++ b/app/main.py @@ -11,6 +11,7 @@ from Article import * import Yaml from user_service import userService from account_service import accountService +from wordCMD import show_bp from admin_service import adminService, ADMIN_NAME app = Flask(__name__) app.secret_key = 'lunch.time!' @@ -19,6 +20,7 @@ app.secret_key = 'lunch.time!' app.register_blueprint(userService) app.register_blueprint(accountService) app.register_blueprint(adminService) +app.register_blueprint(show_bp) path_prefix = '/var/www/wordfreq/wordfreq/' path_prefix = './' # comment this line in deployment -- 2.17.1