from flask import Flask, request, Blueprint, render_template
from UseSqlite import InsertQuery, RecordQuery
TKTK = 'token' # set token
show_bp = Blueprint(
'site',
__name__,
)
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("SELECT * FROM words where user = \'" + name + "\'")
rq.do()
# show the results
record = '' + f"Here are {name}'s words:" + '
'
record += ''
record += ''
record += 'WORDS | '
record += '
'
for r in rq.format_results().split('\n\n'):
record += '%s' % (make_html_paragraph(r))
record += '
'
return record + '\n'