forked from mrlan/EnglishPal
				
			[IMPROVE]:main.py:完型填空请求和计分接口
							parent
							
								
									4870772f1f
								
							
						
					
					
						commit
						241708af9c
					
				
							
								
								
									
										37
									
								
								app/main.py
								
								
								
								
							
							
						
						
									
										37
									
								
								app/main.py
								
								
								
								
							|  | @ -11,6 +11,7 @@ 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 cloze.create_clozeTest import Essay | ||||||
| app = Flask(__name__) | app = Flask(__name__) | ||||||
| app.secret_key = 'lunch.time!' | app.secret_key = 'lunch.time!' | ||||||
| 
 | 
 | ||||||
|  | @ -68,7 +69,8 @@ def mark_word(): | ||||||
|         for word in request.form.getlist('marked'): |         for word in request.form.getlist('marked'): | ||||||
|             lst.append((word, 1)) |             lst.append((word, 1)) | ||||||
|         d = pickle_idea.merge_frequency(lst, lst_history) |         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')) |         return redirect(url_for('mainpage')) | ||||||
|     else:  # 不回应GET请求 |     else:  # 不回应GET请求 | ||||||
|         return 'Under construction' |         return 'Under construction' | ||||||
|  | @ -88,7 +90,8 @@ def mainpage(): | ||||||
|         d = load_freq_history(path_prefix + 'static/frequency/frequency.p') |         d = load_freq_history(path_prefix + 'static/frequency/frequency.p') | ||||||
|         lst_history = pickle_idea.dict2lst(d) |         lst_history = pickle_idea.dict2lst(d) | ||||||
|         d = pickle_idea.merge_frequency(lst, lst_history) |         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) |         return render_template('mainpage_post.html', lst=lst, yml=Yaml.yml) | ||||||
| 
 | 
 | ||||||
|     elif request.method == 'GET':  # when we load a html page |     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) |                                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__': | if __name__ == '__main__': | ||||||
|     ''' |     ''' | ||||||
|     运行程序 |     运行程序 | ||||||
|     ''' |     ''' | ||||||
|     # app.secret_key = os.urandom(16) |  | ||||||
|     # app.run(debug=False, port='6000') |  | ||||||
|     app.run(debug=True) |     app.run(debug=True) | ||||||
|     # app.run(debug=True, port='6000') |  | ||||||
|     # app.run(host='0.0.0.0', debug=True, port='6000') |  | ||||||
|     # print(mod5('123')) |  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue