Nice to meet you. My name is kkatus03. I think there are some places that cannot be reached, but thank you.
The outline is as follows.
--Create an English word book on Google Docs in advance --Read the created English word book and ask questions in a random order
I used to study TOEIC. Of course, I was also devoting myself to studying English words, so I bought a notebook for words and studied. However, as I had more opportunities to use my PC at university, I suffered from some stress that I didn't feel in high school.
――Frustrated to write letters by hand ――Luggage increases ・ I can't study if I forget my notebook at home
I gradually felt the inefficiency of paper media, and thought, "Is it possible to manage it using the cloud such as Google Docs?" If it can be realized, it will be possible to add English words without stress regardless of location or device (even from a smartphone, if you use a dedicated keyboard).
In addition, I wondered if the words could be randomly asked in a quiz format. Because
――If the words are in order, the words that are easy to remember will be biased. ――I remember connecting words written on the same page
Because.
In English, the actual object must come to the surface the moment you see the English word. For example
We must be able to do this with every word. To master this, I felt that it was best to practice on a daily basis with the "function to randomly ask words in a quiz format".
Create a document on Google Drive (whatever the name)
Make "Available to everyone who knows the link" in the sharing settings of the created document.
Write the word data in csv format in the created document.
And so on "English words" "Half-width comma" "Japanese translation" It's okay if you write in the format. 4. Paste the document link into the space provided on the second line of code below
Of course, the next time you run it, you should be asked in a different order than last time!
To briefly explain the program,
--Get the HTML file of the word book and extract only the word data (scraping) --Store word data in an array --Random questions
It's like that.
The following three are the main functions created.
--DLwordnote function
[Argument] URL of Google Docs Wordbook [Return value] A character string in which only word data is extracted from the html file of the word book. The extraction method is rough, so I will omit it.
--Make_Data function
[Argument] Word data extracted by DLwordnote [Return value] Array containing word data Use the csv module to store in a two-dimensional array.
--Quiz function
[Argument] An array that stores the word data created by Make_Data. [Return value] None Use the random module to ask questions in no particular order.
Assuming Python 3. ○. Since the purpose was to realize the function, I made it with little knowledge.
word_practice.py
def main():
Quiz(Make_Data(DLwordnote('Specified URL')))
print("well played!!")
import urllib.request as req
def DLwordnote(url):
response = req.urlopen(url) #Open HTML file by specifying URL
html_data=(str(response.read(),'utf-8_sig'))#html_Put all the html in a variable called data
response.close()
#print(html_data)
word_data=''#Create word-only data here
startwords='DOCS_modelChunk = [{"ty":"is","ibi":'#In html word data starts with this sentence(Should be)
while(html_data.find(startwords)!=-1):
startpoint = html_data.find(startwords)+len(startwords)#What character is the starting point
html_data=extract(html_data,startpoint,len(html_data))#Cut to the beginning of word data
i=0#,"s":"What number counting from
while True:#"Until you find
if (html_data[html_data.find(',"s":"')+len(',"s":"')+i]=='"'):#"If is found, loop out
break
word_data+=str(html_data[html_data.find(',"s":"')+len(',"s":"')+i])#The previous html_word extracted only words from data_Assign to a variable called data
#With this,\n is not recognized as a line feed code
i+=1
dammy="\\"+"n"#Not a line feed code\n
#print(word_data.replace(dammy,"\n"))
return (word_data.replace(dammy,"\n"))#Returns the read csv string
import random
import csv
def Make_Data(csv_data):#Read csv string from file
#I tried to use as few arrays as possible
list_data=csv_data.split("\n")#The csv string is separated as an element of list based on the line feed,_Assign to data
list_data=[n for n in list_data if (n!='\n') and (n!='') and (n!=' ')]#Work to remove invalid values
for i in range(len(list_data)):#list_Separate data into elements within each element based on commas
list_data[i]=list_data[i].split(",")
#print(list_data)
return list_data#List containing csv list_Returns data
def Quiz(list_data):
#Create a list called check to note whether each question was asked(below),0:undo,1:done
check=[0]*len(list_data)#For the time being, make a list with all 0 elements with the same length as data
total=0#Make a note of how many questions were asked
while True:#loop
num=random.randint(0,len(list_data)-1)#Substitute the problem number for num (random)
if(check[num]==0):#If it hasn't been asked yet
print("[%d/%d]" % (total+1,len(list_data)))#Screen output and questions
#press enter key
input("%s" % (list_data[num][0]))
print("%s\n" % (list_data[num][1]))#Screen output and questions
check[num]=1#Make a note as already mentioned,
total+=1#1 count up
if(total==len(list_data)):#If all the questions are asked
break#Unloop
def extract(data,a,b):#String data a,Extract up to b
tmp=''
for i in range(a,b):
tmp+=data[i]
return tmp
if __name__=="__main__":
main()
In this program
--Create an English word book on Google Docs in advance --Read the created English word book and ask questions in a random order
Realized the function. It's a rough code, but I did this program every day while commuting to school, and I increased my TOEIC score from 400 points to the latter half of 600 points.
As a future issue
--Study html and realize to extract word data neatly ――I want to study the front end side and actually release it as an app
That can be mentioned.
I will post again if I can improve it!
Recommended Posts