From 241708af9c443d1a324c55fffde7b213cd329f81 Mon Sep 17 00:00:00 2001 From: stfujnkk <3365310020@qq.com> Date: Fri, 10 Jun 2022 19:24:58 +0800 Subject: [PATCH] =?UTF-8?q?[IMPROVE]:main.py:=E5=AE=8C=E5=9E=8B=E5=A1=AB?= =?UTF-8?q?=E7=A9=BA=E8=AF=B7=E6=B1=82=E5=92=8C=E8=AE=A1=E5=88=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/cloze/__init__.py | 0 app/main.py | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 app/cloze/__init__.py diff --git a/app/cloze/__init__.py b/app/cloze/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/main.py b/app/main.py index d903bf4..3b3b3b7 100644 --- a/app/main.py +++ b/app/main.py @@ -11,6 +11,7 @@ from Article import * import Yaml from user_service import userService from account_service import accountService +from cloze.create_clozeTest import Essay app = Flask(__name__) app.secret_key = 'lunch.time!' @@ -68,9 +69,10 @@ def mark_word(): for word in request.form.getlist('marked'): lst.append((word, 1)) d = pickle_idea.merge_frequency(lst, lst_history) - pickle_idea.save_frequency_to_pickle(d, path_prefix + 'static/frequency/frequency.p') + pickle_idea.save_frequency_to_pickle( + d, path_prefix + 'static/frequency/frequency.p') return redirect(url_for('mainpage')) - else: # 不回应GET请求 + else: # 不回应GET请求 return 'Under construction' @@ -88,7 +90,8 @@ def mainpage(): d = load_freq_history(path_prefix + 'static/frequency/frequency.p') lst_history = pickle_idea.dict2lst(d) d = pickle_idea.merge_frequency(lst, lst_history) - pickle_idea.save_frequency_to_pickle(d, path_prefix + 'static/frequency/frequency.p') + pickle_idea.save_frequency_to_pickle( + d, path_prefix + 'static/frequency/frequency.p') return render_template('mainpage_post.html', lst=lst, yml=Yaml.yml) elif request.method == 'GET': # when we load a html page @@ -101,14 +104,34 @@ def mainpage(): d_len=d_len, lst=lst, yml=Yaml.yml) +essay = Essay() + + +@app.route('/goCroze', methods=['GET', 'POST']) +def go_ClozeTest(): + if request.method == 'GET': + essay._article_id += 1 + essay.create_crozeTest(essay) + + return render_template('clozeTest.html', essay=essay, answers=None) + if request.method == 'POST': + score = 0 + # submit_answers = [] + questions = essay._questions + answers = essay._answers + + for i in range(0, len(answers)): + ans = request.form.get('answer' + str(i+1)) + if ans: + ans = ans.upper() + no = ord(ans)-ord('A') + if questions[i][no] == answers[i]: + score += 10 + return render_template('clozeTest.html', essay=essay, msg=f'你的分数是: {score}', answers=answers) + if __name__ == '__main__': ''' 运行程序 ''' - # app.secret_key = os.urandom(16) - # app.run(debug=False, port='6000') app.run(debug=True) - # app.run(debug=True, port='6000') - # app.run(host='0.0.0.0', debug=True, port='6000') - # print(mod5('123'))