-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
221 lines (175 loc) · 6.75 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from datetime import datetime
from openpyxl import Workbook
from openpyxl import load_workbook
import os
from selenium import webdriver
import requests
from webdriver_manager.chrome import ChromeDriverManager
import urllib.request
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
driver = webdriver.Chrome(ChromeDriverManager().install())
username = 'your_uesrname'
password = 'your_password'
def get_verb(verb):
driver.get('https://www.verbix.com/webverbix/German/{}.html'.format(verb))
past = driver.find_element_by_xpath('/html/body/div[2]/div[3]/div/section/div/div[3]/div[1]/div[3]/table/tbody/tr[1]/td[2]')
perfect = driver.find_element_by_xpath('//*[@id="verbixConjugations"]/section/div/div[3]/div[1]/div[2]/table/tbody/tr[3]/td[2]')
return past.text+' ;'+perfect.text
def get_sound(word):
url = "https://www.howtopronounce.com/german/{}".format(word)
driver.get(url)
url2 = driver.find_element_by_xpath("/html/body/main/div/section[2]/div[1]/div[2]/div/section[2]/div/article[1]/div/div/span/audio").get_attribute('src')
re = requests.get(url2)
with open('words/tmp/{}.mp3'.format(word),'wb') as f:
f.write(re.content)
def memrise(data,words):
driver.get("https://app.memrise.com/signin")
username = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/form/div[1]/div/input')
username.send_keys(username)
password = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/form/div[2]/div/input')
password.send_keys(password)
button = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/form/div[3]/div[1]/button')
button.click()
sleep(5)
driver.get('https://app.memrise.com/course/5947047/german-b1-word/edit')
button = driver.find_element_by_xpath('/html/body/div[3]/div[5]/div/div[1]/div[2]/div/button')
button.click()
button = driver.find_element_by_xpath('/html/body/div[3]/div[5]/div/div[1]/div[2]/div/ul/li[1]/a')
button.click()
sleep(6)
levels = driver.find_elements_by_class_name('level')
current = levels[-1]
actions = ActionChains(driver)
actions.move_to_element(current).perform()
button = driver.find_element_by_xpath('/html/body/div[3]/div[5]/div/div[2]/div[{}]/div[2]/div/div/div/button'.format(len(levels)))
# print(button.text)
button.click()
button = driver.find_element_by_xpath('/html/body/div[3]/div[5]/div/div[2]/div[{}]/div[2]/div/div/div/ul/li/a'.format(len(levels)))
button.click()
sleep(3)
# inp = driver.find_element_by_xpath('/html/body/div[4]/div/div/div[2]/form/div[2]')
# inp.send_keys(data)
pop = driver.find_element_by_xpath('/html/body/div[4]/div/div/div[2]/form/div[2]/textarea')
pop.send_keys(data)
sleep(1)
button = driver.find_element_by_xpath('/html/body/div[4]/div/div/div[2]/form/div[1]/div/label[2]/input')
button.click()
button = driver.find_element_by_xpath('/html/body/div[4]/div/div/div[3]/a[2]')
button.click()
sleep(5)
for i in range(len(words)):
audio = driver.find_element_by_xpath('/html/body/div[3]/div[5]/div/div[2]/div[{level}]/div[3]/table/tbody[1]/tr[{word}]/td[5]/div/div[1]/input'.format(level = len(levels),word=i+1))
#actions.move_to_element(audio).perform()
sleep(2)
wd = words[i]
if words[i] == 'skip':
continue
else:
audio.send_keys('/home/mjandar12/Desktop/german/words/tmp/{}.mp3'.format(words[i]))
def store_words(german, meaning):
wb = Workbook()
ws = wb.active
d = os.listdir('words')
artikel = ['der','das','die','Der','Das','Die']
words = []
words_m = []
verbs = []
verbs_m = []
verbs_past = []
adjectives = []
adjectives_m = []
data = ''
for c,word in enumerate(german):
if word[:3] in artikel:
german[c] = word[4:]
words_m.append(meaning[c])
words.append(word)
data += '{word},{meaning}\n'.format(word = word,meaning=meaning[c])
elif word[-2:] == 'en':
verbs_m.append(meaning[c])
verbs.append(word)
verbs_past.append(get_verb(word))
data += '{word},{meaning},{extra}\n'.format(word = word,meaning=meaning[c],extra = verbs_past[-1])
else:
adjectives_m.append(meaning[c])
adjectives.append(word)
data += '{word},{meaning}\n'.format(word = word,meaning=meaning[c])
if word[-1] != '-':
get_sound(german[c])
ws.cell(row=1,column=1).value = "nouns"
n = 2
for i in range(len(words)):
ws.cell(row=n, column=1).value = words[i]
ws.cell(row=n, column=2).value = words_m[i]
n +=1
ws.cell(row=n,column=1).value = "verbs"
n +=1
for i in range(len(verbs)):
ws.cell(row=n, column=1).value = verbs[i]
ws.cell(row=n, column=2).value = verbs_m[i]
ws.cell(row=n, column=3).value = verbs_past[i]
n +=1
ws.cell(row=n,column=1).value = "adjectives"
n +=1
for i in range(len(adjectives)):
ws.cell(row=n, column=1).value = adjectives[i]
ws.cell(row=n, column=2).value = adjectives_m[i]
n +=1
wb.save("words/group{}.xlsx".format(len(d)))
memrise(data,german)
def word_input():
words = []
meanings = []
while True:
word = input("german word: ")
if word == 'save -a':
store_words(words,meanings)
memrise(words,meanings)
break
elif word == 'quit':
store_words(words,meanings)
break
meaning = input("meaning: ")
words.append(word)
meanings.append(meaning)
inp = input("number of words to enter: ")
if inp == "i":
word_input()
elif inp == "load":
file = int(input("file number to load:"))
wb = load_workbook("words/group{}.xlsx".format(file))
sheet = wb.active
n = 2
st = 0
words = []
data = ''
while True:
cell1 = sheet.cell(row=n,column=1).value
if cell1 == None:
break
if cell1 == "verbs":
st = 1
elif cell1 == "adjectives":
st = 2
else:
word = cell1
meaning = sheet.cell(row=n,column=2).value
if st ==1 :
data = data + word + "," + meaning + '\n'
else:
data = data + word + "," + meaning +'\n'
if word[-1] != '-':
if st == 0:
get_sound(word[4:])
words.append(word[4:])
else:
get_sound(word)
words.append(word)
else:
words.append("skip")
print(data)
n+=1
print(data)
memrise(data,words)
driver.close()