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