0
0
Fork 0

Compare commits

...

3 Commits

Author SHA1 Message Date
钱骏琪 9b276cc454 Merge branch 'master' into improvment-NiWeiCong 2023-05-06 19:05:16 +08:00
Blueotter fa44bc9126 add more comments and sql file 2022-06-18 22:16:18 +08:00
Blueotter d7b40ee699 add wordCMD.py 2022-06-18 16:17:08 +08:00
3 changed files with 61 additions and 0 deletions

View File

@ -12,12 +12,14 @@ from Article import *
import Yaml import Yaml
from user_service import userService from user_service import userService
from account_service import accountService from account_service import accountService
from wordCMD import show_bp
app = Flask(__name__) app = Flask(__name__)
app.secret_key = 'lunch.time!' app.secret_key = 'lunch.time!'
# 将蓝图注册到Lab app # 将蓝图注册到Lab app
app.register_blueprint(userService) app.register_blueprint(userService)
app.register_blueprint(accountService) app.register_blueprint(accountService)
app.register_blueprint(show_bp)
path_prefix = '/var/www/wordfreq/wordfreq/' path_prefix = '/var/www/wordfreq/wordfreq/'
path_prefix = './' # comment this line in deployment path_prefix = './' # comment this line in deployment

18
app/static/words.sql Normal file
View File

@ -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');

41
app/wordCMD.py Normal file
View File

@ -0,0 +1,41 @@
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 = '<tr><td>' + word + '</td></tr>'
return result
@show_bp.route('/show/<name>/') # set route for show page <name> 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 = '<h1>' + f"Here are {name}'s words:" + '</h1>'
record += '<table border= \"2\" >'
record += '<tr>'
record += '<th>WORDS</th>'
record += '</tr>'
for r in rq.format_results().split('\n\n'):
record += '%s' % (make_html_paragraph(r))
record += '</table>'
return record + '\n'