From fa44bc91264afd4aecd5eed2e41af451da8e80de Mon Sep 17 00:00:00 2001 From: Blueotter Date: Sat, 18 Jun 2022 22:16:18 +0800 Subject: [PATCH] add more comments and sql file --- app/static/words.sql | 18 ++++++++++++++++++ app/wordCMD.py | 17 ++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 app/static/words.sql diff --git a/app/static/words.sql b/app/static/words.sql new file mode 100644 index 0000000..7b0b44c --- /dev/null +++ b/app/static/words.sql @@ -0,0 +1,18 @@ +PRAGMA foreign_keys = OFF; + + +DROP TABLE IF EXISTS "main"."words"; +CREATE TABLE "words" ( +"user" TEXT NOT NULL, +"word" TEXT NOT NULL +); + + +INSERT INTO "main"."words" VALUES ('jack', 'numb'); +INSERT INTO "main"."words" VALUES ('jack', 'faint'); +INSERT INTO "main"."words" VALUES ('alice', 'tube'); +INSERT INTO "main"."words" VALUES ('alice', 'cake'); +INSERT INTO "main"."words" VALUES ('tom', 'kite'); +INSERT INTO "main"."words" VALUES ('tom', 'fly'); +INSERT INTO "main"."words" VALUES ('jack', 'be'); +INSERT INTO "main"."words" VALUES ('jack', 'fly'); diff --git a/app/wordCMD.py b/app/wordCMD.py index f5cfdd6..94546ce 100644 --- a/app/wordCMD.py +++ b/app/wordCMD.py @@ -1,7 +1,7 @@ from flask import Flask, request, Blueprint, render_template from UseSqlite import InsertQuery, RecordQuery -TKTK = 'token' +TKTK = 'token' # set token show_bp = Blueprint( 'site', @@ -9,7 +9,7 @@ show_bp = Blueprint( ) -def make_html_paragraph(s): +def make_html_paragraph(s): # build the word's table if s.strip() == '': return '' lst = s.split(',') @@ -18,25 +18,24 @@ def make_html_paragraph(s): return result -@show_bp.route('/show//') +@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("SELECT * FROM words where user = \'" + name + "\'") rq.do() - - record = '

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

' + # show the results + 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' + return record + '\n'