add more comments and sql file
parent
d7b40ee699
commit
fa44bc9126
|
@ -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');
|
|
@ -1,7 +1,7 @@
|
||||||
from flask import Flask, request, Blueprint, render_template
|
from flask import Flask, request, Blueprint, render_template
|
||||||
from UseSqlite import InsertQuery, RecordQuery
|
from UseSqlite import InsertQuery, RecordQuery
|
||||||
|
|
||||||
TKTK = 'token'
|
TKTK = 'token' # set token
|
||||||
|
|
||||||
show_bp = Blueprint(
|
show_bp = Blueprint(
|
||||||
'site',
|
'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() == '':
|
if s.strip() == '':
|
||||||
return ''
|
return ''
|
||||||
lst = s.split(',')
|
lst = s.split(',')
|
||||||
|
@ -18,25 +18,24 @@ def make_html_paragraph(s):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@show_bp.route('/show/<name>/')
|
@show_bp.route('/show/<name>/') # set route for show page <name> means the var name to search
|
||||||
def show(name):
|
def show(name):
|
||||||
token = request.args.get("token")
|
token = request.args.get("token")
|
||||||
|
# when token is wrong
|
||||||
if token != TKTK:
|
if token != TKTK:
|
||||||
return "token is wrong, please try again"
|
return "token is wrong, please try again"
|
||||||
|
|
||||||
rq = RecordQuery('./static/wordfreqapp.db')
|
rq = RecordQuery('./static/wordfreqapp.db')
|
||||||
|
# search the user's words in db
|
||||||
rq.instructions("SELECT * FROM words where user = \'" + name + "\'")
|
rq.instructions("SELECT * FROM words where user = \'" + name + "\'")
|
||||||
rq.do()
|
rq.do()
|
||||||
|
# show the results
|
||||||
record = '<h1>' + f"Here are {name}'s words:" + '</h1>'
|
record = '<h1>' + f"Here are {name}'s words:" + '</h1>'
|
||||||
record += '<table border= \"2\" >'
|
record += '<table border= \"2\" >'
|
||||||
record += '<tr>'
|
record += '<tr>'
|
||||||
record += '<th>WORDS</th>'
|
record += '<th>WORDS</th>'
|
||||||
record += '</tr>'
|
record += '</tr>'
|
||||||
# record += '<tr>'
|
|
||||||
for r in rq.format_results().split('\n\n'):
|
for r in rq.format_results().split('\n\n'):
|
||||||
record += '%s' % (make_html_paragraph(r))
|
record += '%s' % (make_html_paragraph(r))
|
||||||
# record += '</tr>'
|
|
||||||
record += '</table>'
|
record += '</table>'
|
||||||
return record + '\n'
|
return record + '\n'
|
||||||
|
|
Loading…
Reference in New Issue