pylint:fixed 2 remove redundant comments
parent
782783040a
commit
e19d1ae51b
|
@ -9,10 +9,6 @@ path_prefix = './' # comment this line in deployment
|
||||||
|
|
||||||
|
|
||||||
def total_number_of_essays():
|
def total_number_of_essays():
|
||||||
'''
|
|
||||||
得到文章总数
|
|
||||||
return:文章数目
|
|
||||||
'''
|
|
||||||
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
|
rq = RecordQuery(path_prefix + 'static/wordfreqapp.db')
|
||||||
rq.instructions("SELECT * FROM article")
|
rq.instructions("SELECT * FROM article")
|
||||||
rq.do()
|
rq.do()
|
||||||
|
@ -21,16 +17,10 @@ def total_number_of_essays():
|
||||||
|
|
||||||
|
|
||||||
def get_article_title(s):
|
def get_article_title(s):
|
||||||
'''
|
|
||||||
得到文章的标题
|
|
||||||
'''
|
|
||||||
return s.split('\n')[0]
|
return s.split('\n')[0]
|
||||||
|
|
||||||
|
|
||||||
def get_article_body(s):
|
def get_article_body(s):
|
||||||
'''
|
|
||||||
得到文章的内容
|
|
||||||
'''
|
|
||||||
lst = s.split('\n')
|
lst = s.split('\n')
|
||||||
lst.pop(0) # remove the first line
|
lst.pop(0) # remove the first line
|
||||||
return '\n'.join(lst)
|
return '\n'.join(lst)
|
||||||
|
@ -116,9 +106,6 @@ def get_today_article(user_word_list, visited_articles):
|
||||||
|
|
||||||
|
|
||||||
def load_freq_history(path):
|
def load_freq_history(path):
|
||||||
'''
|
|
||||||
加载历史路径
|
|
||||||
'''
|
|
||||||
d = {}
|
d = {}
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
d = pickle_idea.load_record(path)
|
d = pickle_idea.load_record(path)
|
||||||
|
@ -126,16 +113,10 @@ def load_freq_history(path):
|
||||||
|
|
||||||
|
|
||||||
def within_range(x, y, r):
|
def within_range(x, y, r):
|
||||||
'''
|
|
||||||
判断x>y并且x-y<=r
|
|
||||||
'''
|
|
||||||
return x > y and abs(x - y) <= r
|
return x > y and abs(x - y) <= r
|
||||||
|
|
||||||
|
|
||||||
def get_question_part(s):
|
def get_question_part(s):
|
||||||
'''
|
|
||||||
得到问题部分
|
|
||||||
'''
|
|
||||||
s = s.strip()
|
s = s.strip()
|
||||||
result = []
|
result = []
|
||||||
flag = 0
|
flag = 0
|
||||||
|
@ -152,9 +133,6 @@ def get_question_part(s):
|
||||||
|
|
||||||
|
|
||||||
def get_answer_part(s):
|
def get_answer_part(s):
|
||||||
'''
|
|
||||||
得到答案部分
|
|
||||||
'''
|
|
||||||
s = s.strip()
|
s = s.strip()
|
||||||
result = []
|
result = []
|
||||||
flag = 0
|
flag = 0
|
||||||
|
|
15
app/Login.py
15
app/Login.py
|
@ -17,26 +17,17 @@ path_prefix = '/var/www/wordfreq/wordfreq/'
|
||||||
path_prefix = './' # comment this line in deployment
|
path_prefix = './' # comment this line in deployment
|
||||||
|
|
||||||
def verify_pass(newpass,oldpass):
|
def verify_pass(newpass,oldpass):
|
||||||
'''
|
|
||||||
判断新旧密码是否相同
|
|
||||||
'''
|
|
||||||
if newpass==oldpass:
|
if newpass==oldpass:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def verify_user(username, password):
|
def verify_user(username, password):
|
||||||
'''
|
|
||||||
判断用户名密码是否正确
|
|
||||||
'''
|
|
||||||
user = get_user_by_username(username)
|
user = get_user_by_username(username)
|
||||||
encoded_password = md5(username + password)
|
encoded_password = md5(username + password)
|
||||||
return user is not None and user.password == encoded_password
|
return user is not None and user.password == encoded_password
|
||||||
|
|
||||||
|
|
||||||
def add_user(username, password):
|
def add_user(username, password):
|
||||||
'''
|
|
||||||
添加新用户
|
|
||||||
'''
|
|
||||||
start_date = datetime.now().strftime('%Y%m%d')
|
start_date = datetime.now().strftime('%Y%m%d')
|
||||||
expiry_date = (datetime.now() + timedelta(days=30)).strftime('%Y%m%d') # will expire after 30 days
|
expiry_date = (datetime.now() + timedelta(days=30)).strftime('%Y%m%d') # will expire after 30 days
|
||||||
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
|
# 将用户名和密码一起加密,以免暴露不同用户的相同密码
|
||||||
|
@ -45,9 +36,6 @@ def add_user(username, password):
|
||||||
|
|
||||||
|
|
||||||
def check_username_availability(username):
|
def check_username_availability(username):
|
||||||
'''
|
|
||||||
检查用户名是否可用
|
|
||||||
'''
|
|
||||||
existed_user = get_user_by_username(username)
|
existed_user = get_user_by_username(username)
|
||||||
return existed_user is None
|
return existed_user is None
|
||||||
|
|
||||||
|
@ -70,9 +58,6 @@ def change_password(username, old_password, new_password):
|
||||||
|
|
||||||
|
|
||||||
def get_expiry_date(username):
|
def get_expiry_date(username):
|
||||||
'''
|
|
||||||
获得过期日期
|
|
||||||
'''
|
|
||||||
user = get_user_by_username(username)
|
user = get_user_by_username(username)
|
||||||
if user is None:
|
if user is None:
|
||||||
return '20191024'
|
return '20191024'
|
||||||
|
|
|
@ -13,10 +13,6 @@ _page_size = 5 # article sizes per page
|
||||||
adminService = Blueprint("admin_service", __name__)
|
adminService = Blueprint("admin_service", __name__)
|
||||||
|
|
||||||
def check_is_admin():
|
def check_is_admin():
|
||||||
'''
|
|
||||||
判断是否是管理员登录
|
|
||||||
:return:不同页面和结果
|
|
||||||
'''
|
|
||||||
# 未登录,跳转到未登录界面
|
# 未登录,跳转到未登录界面
|
||||||
if not session.get("logged_in"):
|
if not session.get("logged_in"):
|
||||||
return render_template("not_login.html")
|
return render_template("not_login.html")
|
||||||
|
|
|
@ -12,9 +12,6 @@ from wordfreqCMD import remove_punctuation, freq, sort_in_descending_order, sort
|
||||||
|
|
||||||
|
|
||||||
def load_record(pickle_fname):
|
def load_record(pickle_fname):
|
||||||
'''
|
|
||||||
得到特定pickle文件中的数据
|
|
||||||
'''
|
|
||||||
with open(pickle_fname, 'rb') as f:
|
with open(pickle_fname, 'rb') as f:
|
||||||
d = pickle.load(f)
|
d = pickle.load(f)
|
||||||
return d
|
return d
|
||||||
|
@ -117,9 +114,6 @@ def user_difficulty_level(d_user, d):
|
||||||
|
|
||||||
|
|
||||||
def text_difficulty_level(s, d):
|
def text_difficulty_level(s, d):
|
||||||
'''
|
|
||||||
得到用文章的难度水平
|
|
||||||
'''
|
|
||||||
s = remove_punctuation(s)
|
s = remove_punctuation(s)
|
||||||
L = freq(s)
|
L = freq(s)
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ def merge_frequency(lst1, lst2):
|
||||||
|
|
||||||
def load_record(pickle_fname):
|
def load_record(pickle_fname):
|
||||||
with open(pickle_fname, 'rb') as f:
|
with open(pickle_fname, 'rb') as f:
|
||||||
d=pickle.load(f)
|
d = pickle.load(f)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ def save_frequency_to_pickle(d, pickle_fname):
|
||||||
pickle.dump(d2, f)
|
pickle.dump(d2, f)
|
||||||
|
|
||||||
def unfamiliar(path,word):
|
def unfamiliar(path,word):
|
||||||
f = open(path,"rb")
|
with open(path,"rb") as f:
|
||||||
dic = pickle.load(f)
|
dic = pickle.load(f)
|
||||||
dic[word] += [datetime.now().strftime('%Y%m%d%H%M')]
|
dic[word] += [datetime.now().strftime('%Y%m%d%H%M')]
|
||||||
fp = open(path,"wb")
|
with open(path,"wb") as fp:
|
||||||
pickle.dump(dic,fp)
|
pickle.dump(dic,fp)
|
||||||
|
|
||||||
def familiar(path,word):
|
def familiar(path,word):
|
||||||
f = open(path,"rb")
|
f = open(path,"rb")
|
||||||
|
|
|
@ -16,9 +16,6 @@ path_prefix = './' # comment this line in deployment
|
||||||
|
|
||||||
@userService.route("/get_next_article/<username>",methods=['GET','POST'])
|
@userService.route("/get_next_article/<username>",methods=['GET','POST'])
|
||||||
def get_next_article(username):
|
def get_next_article(username):
|
||||||
'''
|
|
||||||
得到下一篇文章
|
|
||||||
'''
|
|
||||||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_{username}.pickle'
|
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_{username}.pickle'
|
||||||
session['old_articleID'] = session.get('articleID')
|
session['old_articleID'] = session.get('articleID')
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -40,9 +37,6 @@ def get_next_article(username):
|
||||||
|
|
||||||
@userService.route("/get_pre_article/<username>",methods=['GET'])
|
@userService.route("/get_pre_article/<username>",methods=['GET'])
|
||||||
def get_pre_article(username):
|
def get_pre_article(username):
|
||||||
'''
|
|
||||||
得到上一篇文章
|
|
||||||
'''
|
|
||||||
user_freq_record = path_prefix + 'static/frequency/' + f'frequency_{username}.pickle'
|
user_freq_record = path_prefix + 'static/frequency/' + f'frequency_{username}.pickle'
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
visited_articles = session.get("visited_articles")
|
visited_articles = session.get("visited_articles")
|
||||||
|
|
|
@ -38,9 +38,6 @@ def file2str(fname):#文件转字符
|
||||||
|
|
||||||
|
|
||||||
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
|
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
|
||||||
'''
|
|
||||||
删除文本里的标点符号
|
|
||||||
'''
|
|
||||||
special_characters = r'\_©~<=>+/[]*&$%^@.,?!:;#()"“”—‘’{}|' # 把里面的字符都去掉
|
special_characters = r'\_©~<=>+/[]*&$%^@.,?!:;#()"“”—‘’{}|' # 把里面的字符都去掉
|
||||||
for c in special_characters:
|
for c in special_characters:
|
||||||
s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
|
s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
|
||||||
|
|
Loading…
Reference in New Issue