Merge pull request #5 from lanlab-org/SPM-Spring2021-2600-朱文琦201836900114
Spm spring2021 2600 朱文琦201836900114 Thanks 朱文琦. For more information about this Pull Request. See the following Kanban: http://118.25.96.118/kanboard/?controller=BoardViewController&action=readonly&token=746d456a7fc60ccd5ab4dd015dcf3b9dbdddd3207fc26185c956d658bc2f -Huipull/1/head
						commit
						3f0006fa4c
					
				|  | @ -7,6 +7,5 @@ app/static/img/ | ||||||
| app/static/frequency/frequency_*.pickle | app/static/frequency/frequency_*.pickle | ||||||
| app/static/frequency/frequency.p | app/static/frequency/frequency.p | ||||||
| app/static/wordfreqapp.db | app/static/wordfreqapp.db | ||||||
| app/static/wordfreqapp.sql |  | ||||||
| app/static/donate-the-author.jpg | app/static/donate-the-author.jpg | ||||||
| app/static/donate-the-author-hidden.jpg | app/static/donate-the-author-hidden.jpg | ||||||
|  |  | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | FROM tiangolo/uwsgi-nginx-flask:python3.6 | ||||||
|  | COPY ./app /app | ||||||
|  | @ -0,0 +1,34 @@ | ||||||
|  | pipeline { | ||||||
|  |     agent any | ||||||
|  | 
 | ||||||
|  |     stages { | ||||||
|  |         stage('MakeDatabasefile') { | ||||||
|  | 	    steps { | ||||||
|  | 	        sh 'touch ./app/static/wordfreqapp.db && rm -f ./app/static/wordfreqapp.db'  | ||||||
|  | 	        sh 'cat ./app/static/wordfreqapp.sql | sqlite3 ./app/static/wordfreqapp.db' | ||||||
|  | 	    } | ||||||
|  | 	} | ||||||
|  |         stage('BuildIt') { | ||||||
|  |             steps { | ||||||
|  |                 echo 'Building..' | ||||||
|  | 		sh 'sudo docker build -t englishpal .' | ||||||
|  | 		sh 'sudo docker stop $(docker ps -aq)' | ||||||
|  | 		sh 'sudo docker run -d -p 91:80 -v /var/lib/jenkins/workspace/EnglishPal_Pipeline_master/app/static/frequency:/app/static/frequency -t englishpal' | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         stage('TestIt') { | ||||||
|  |             steps { | ||||||
|  |                 echo 'Testing..' | ||||||
|  | 		sh 'sudo docker run -d -p 4444:4444 selenium/standalone-chrome' | ||||||
|  | 		sh 'pip3 install pytest -U -q' | ||||||
|  | 		sh 'pip3 install selenium -U -q' | ||||||
|  | 		sh 'python3 -m pytest -v -s ./app/test' | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         stage('DeployIt') { | ||||||
|  |             steps { | ||||||
|  |                 echo 'Deploying....' | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,6 @@ | ||||||
|  | 在生词簿每个单词后面,加上两个按钮,熟悉与不熟悉: | ||||||
|  | 1.如果点熟悉,就将生词簿中该单词后面记录的添加次数减一,直至减为0,就将该单词从生词簿中移除。 | ||||||
|  | 2.如果点不熟悉,就将生词簿中该单词后面记录的添加次数加一。 | ||||||
|  | 
 | ||||||
|  | - 朱文绮 | ||||||
|  | 
 | ||||||
							
								
								
									
										19
									
								
								app/main.py
								
								
								
								
							
							
						
						
									
										19
									
								
								app/main.py
								
								
								
								
							|  | @ -270,6 +270,17 @@ def user_mark_word(username): | ||||||
|         return 'Under construction' |         return 'Under construction' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @app.route("/<username>/<word>/unfamiliar", methods=['GET', 'POST']) | ||||||
|  | def unfamiliar(username,word): | ||||||
|  |     user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username) | ||||||
|  |     pickle_idea.unfamiliar(user_freq_record,word) | ||||||
|  |     return redirect(url_for('userpage', username=username)) | ||||||
|  | 
 | ||||||
|  | @app.route("/<username>/<word>/familiar", methods=['GET', 'POST']) | ||||||
|  | def familiar(username,word): | ||||||
|  |     user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username) | ||||||
|  |     pickle_idea.familiar(user_freq_record,word) | ||||||
|  |     return redirect(url_for('userpage', username=username)) | ||||||
| 
 | 
 | ||||||
| @app.route("/<username>", methods=['GET', 'POST']) | @app.route("/<username>", methods=['GET', 'POST']) | ||||||
| def userpage(username): | def userpage(username): | ||||||
|  | @ -345,13 +356,11 @@ def userpage(username): | ||||||
|                 freq = x[1] |                 freq = x[1] | ||||||
|                 if isinstance(d[word], list): # d[word] is a list of dates |                 if isinstance(d[word], list): # d[word] is a list of dates | ||||||
|                     if freq > 1: |                     if freq > 1: | ||||||
|                         page += '<p class="new-word"> <a href="%s">%s</a>                     (<a title="%s">%d</a>) </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq) |                         page += '<p class="new-word"> <a href="%s">%s</a>(<a title="%s">%d</a>) <a href="%s/%s/familiar">熟悉</a> <a href="%s/%s/unfamiliar">不熟悉</a>  </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word) | ||||||
|                     else: |                     else: | ||||||
|                         page += '<p class="new-word"> <a href="%s">%s</a> <font color="white">(<a title="%s">%d</a>)</font> </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq) |                         page += '<p class="new-word"> <a href="%s">%s</a>(<a title="%s">%d</a>) <a href="%s/%s/familiar">熟悉</a> <a href="%s/%s/unfamiliar">不熟悉</a>   </p>\n' % (youdao_link(word), word, '; '.join(d[word]), freq,username, word,username,word) | ||||||
|                 elif isinstance(d[word], int): # d[word] is a frequency. to migrate from old format. |                 elif isinstance(d[word], int): # d[word] is a frequency. to migrate from old format. | ||||||
|                     page += '<a href="%s">%s</a>%d\n' % (youdao_link(word), word, freq)                     |                     page += '<a href="%s">%s</a>%d\n' % (youdao_link(word), word, freq) | ||||||
|                      |  | ||||||
|                  |  | ||||||
|         return page |         return page | ||||||
| 
 | 
 | ||||||
| ### Sign-up, login, logout ### | ### Sign-up, login, logout ### | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ | ||||||
| # Task: incorporate the functions into wordfreqCMD.py such that it will also show cumulative frequency. | # Task: incorporate the functions into wordfreqCMD.py such that it will also show cumulative frequency. | ||||||
| 
 | 
 | ||||||
| import pickle | import pickle | ||||||
|  | from datetime import datetime | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def lst2dict(lst, d): | def lst2dict(lst, d): | ||||||
|  | @ -53,7 +54,22 @@ def save_frequency_to_pickle(d, pickle_fname): | ||||||
|     pickle.dump(d2, f) |     pickle.dump(d2, f) | ||||||
|     f.close() |     f.close() | ||||||
| 
 | 
 | ||||||
|  | def unfamiliar(path,word): | ||||||
|  |     f = open(path,"rb") | ||||||
|  |     dic = pickle.load(f) | ||||||
|  |     dic[word] += [datetime.now().strftime('%Y%m%d%H%M')] | ||||||
|  |     fp = open(path,"wb") | ||||||
|  |     pickle.dump(dic,fp) | ||||||
| 
 | 
 | ||||||
|  | def familiar(path,word): | ||||||
|  |     f = open(path,"rb") | ||||||
|  |     dic = pickle.load(f) | ||||||
|  |     if len(dic[word])>1: | ||||||
|  |         del dic[word][0] | ||||||
|  |     else: | ||||||
|  |         dic.pop(word) | ||||||
|  |     fp = open(path,"wb") | ||||||
|  |     pickle.dump(dic,fp) | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -67,15 +67,5 @@ def test_add_word_and_essay_does_not_change(): | ||||||
|         index = current_essay_content.find('for you.') |         index = current_essay_content.find('for you.') | ||||||
|         assert current_essay_content[index:] == essay_content[index:] |         assert current_essay_content[index:] == essay_content[index:] | ||||||
|      |      | ||||||
|         # click the Next button. Now the essay should change. |  | ||||||
|         elem = driver.find_element_by_link_text('下一篇') # 找到get所有词频按钮 |  | ||||||
|         elem.click() |  | ||||||
|      |  | ||||||
|         # compare again |  | ||||||
|         driver.save_screenshot('./app/test/test_add_word_and_essay_does_not_change_pic2.png') |  | ||||||
|         elem = driver.find_element_by_id('text-content') |  | ||||||
|         next_essay_content = elem.text |  | ||||||
|      |  | ||||||
|         assert current_essay_content[index:] != next_essay_content[index:] |  | ||||||
|     finally: |     finally: | ||||||
|         driver.quit() |         driver.quit() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue