Skip to content

Commit 9e7ac03

Browse files
Fixes in kindle2memrise
1 parent 77e9a88 commit 9e7ac03

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ audio/*.mp3
22
memrise.db
33
memrise.txt
44
vocab.db
5+
variables.py
6+
*.pyc

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For my self-education I use [http://memrise.com/](http://memrise.com/) (both on
2626

2727
I heavily sourced from two GitHub projects:
2828

29-
* [cambridge-cli](https://github.com/pasternak/cambridge-cli/blob/master/cambridge-cli.py)
29+
* [cambridge-cli](https://github.com/pasternak/cambridge-cli)
3030
* [bulk-audio-upload](https://github.com/DrewSSP/bulk-audio-upload)
3131
* [http://jhartman.pl](http://jhartman.pl)
3232

@@ -73,6 +73,19 @@ This is the file, which will be used for [bulk word add](http://feedback.memrise
7373

7474
## Bulk word add
7575

76+
Create a new Course.
77+
78+
In the course, add two new columns: **Definition** and **Example**.
79+
80+
Edit settings for both of new columns, edit attributes:
81+
82+
* *Definition* - edit settings:
83+
* *Display* - only _Show after tests_ is selected
84+
* *Testing* - all options unselected
85+
* *Example* - edit settings:
86+
* *Display* - all options unselected
87+
* *Testing* - only _Tapping Tests Enabled_ is selected
88+
7689
Go to your Course, press Edit and in the Advanced options, look for _Bulk add words_:
7790

7891
![Bulk Add words](http://jhartman.pl/files/memrise/01%20-%20memrise.png)
@@ -81,6 +94,8 @@ Open `memrise.txt` in an editor (e.g. Notepad), select all, copy it and paste in
8194

8295
![Bulk Add words](http://jhartman.pl/files/memrise/02%20-%20memrise.png)
8396

97+
That's it!
98+
8499

85100

86101

kindle2memrise.py

+29-33
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def translate(self):
3535
desc = definition = example = pronunciation = audiofileURL = None
3636

3737
try:
38-
desc = soup.find(attrs={"class": "trans"}).get_text().strip().capitalize()
38+
translation = soup.find(attrs={"class": "trans"}).get_text().strip()
3939
except:
40-
desc = None
40+
translation = None
4141

4242
try:
4343
definition = soup.find(attrs={"class": "def"}).get_text().strip().capitalize()
@@ -47,56 +47,50 @@ def translate(self):
4747
try:
4848
example = soup.find(attrs={"title": "Example"}).get_text().strip()
4949
except:
50-
example = "N/A"
50+
example = None
5151

5252
try:
5353
pronunciation = soup.find(attrs={"class": "ipa"}).get_text().strip()
5454
except:
55-
pronunciation = ""
55+
pronunciation = None
5656

5757
try:
5858
audiofileURL = soup.find(attrs={"data-src-mp3": True}).attrs['data-src-mp3']
5959
except:
6060
audiofileURL = None
61-
61+
62+
if(translation == None):
63+
translation = definition
64+
definition = None
6265

6366
print("\n\033[1m%s:\033[0m" % term)
64-
print("\t>> %s. %s" % (desc, definition) )
67+
print("\t>> %s" % translation )
6568

69+
print("\n[-] Definition:")
70+
print("\t%s\n" % definition)
71+
6672
print("\n[-] Example:")
67-
print("\t{example}\n".format(example=example))
73+
print("\t%s\n" % example)
6874

6975
print("\n[-] Pronunciation:")
70-
print("\t{pronunciation}\n".format(pronunciation=pronunciation))
76+
print("\t%s\n" % pronunciation)
7177

7278
print("\n[-] Audio URL:")
73-
print("\t{url}\n".format(url=audiofileURL))
79+
print("\t%s\n" % audiofileURL)
7480

75-
if(definition != None):
76-
if(desc != None):
77-
self.definition = desc + ". " + definition + ". Example: " + example
78-
else:
79-
self.definition = definition + ". Example: " + example
80-
81-
self.pronunciation = pronunciation
82-
self.audiofileURL = audiofileURL
81+
self.translation = translation
8382

84-
self.audiofilePath = downloadAudioFile(audiofileURL, term)
85-
86-
def __init__(self, word, definition, pronunciation, partofdpeech, gender, audiofileURL, audiofilePath):
87-
self.word = word
8883
self.definition = definition
84+
self.example = example
85+
8986
self.pronunciation = pronunciation
90-
self.partofdpeech = partofdpeech
91-
self.gender = gender
9287
self.audiofileURL = audiofileURL
93-
self.audiofilePath = audiofilePath
9488

95-
self.translate()
96-
89+
self.audiofilePath = downloadAudioFile(audiofileURL, term)
9790

9891
def __init__(self, word):
9992
self.word = word
93+
self.translation = None
10094
self.definition = None
10195
self.pronunciation = None
10296
self.partofdpeech = None
@@ -136,7 +130,7 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
136130
dictionaryDB = DatabaseManager(dictionaryDBFilename)
137131

138132

139-
dictionaryDB.query("CREATE TABLE IF NOT EXISTS dictionary (word TEXT UNIQUE, definition TEXT, pronunciation TEXT, partofdpeech TEXT, gender TEXT, audiofileURL TEXT, audiofilePath TEXT, revision INTEGER)")
133+
dictionaryDB.query("CREATE TABLE IF NOT EXISTS dictionary (word TEXT UNIQUE, translation TEXT, definition TEXT, example TEXT, pronunciation TEXT, partofdpeech TEXT, gender TEXT, audiofileURL TEXT, audiofilePath TEXT, revision INTEGER)")
140134

141135
try:
142136
revisions = dictionaryDB.query("SELECT MAX(revision) FROM dictionary")
@@ -167,10 +161,12 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
167161

168162
translated = Translation(word)
169163

170-
dictionaryDB.query("INSERT INTO dictionary VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
164+
dictionaryDB.query("INSERT INTO dictionary VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
171165
[
172166
translated.word,
167+
translated.translation,
173168
translated.definition,
169+
translated.example,
174170
translated.pronunciation,
175171
translated.partofdpeech,
176172
translated.gender,
@@ -179,7 +175,7 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
179175
revision
180176
] )
181177

182-
if(translated.definition != None):
178+
if(translated.translation != None):
183179
newWords += 1
184180
except sqlite3.Error as e:
185181
print("Skipping.... %s" % e)
@@ -197,7 +193,7 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
197193

198194
outputMemrise(dictionaryDB, revision, outputFilename)
199195

200-
dictionaryDB.query("DELETE FROM dictionary WHERE word=?", [ "retorted" ]);
196+
# dictionaryDB.query("DELETE FROM dictionary WHERE word=?", [ "retorted" ]);
201197

202198
dictionaryDB.close()
203199
kindleDB.close()
@@ -208,7 +204,7 @@ def outputMemrise(dictionaryDB, revision, outputFilename):
208204

209205
try:
210206
with open(outputFilename, 'w') as f:
211-
cursor = dictionaryDB.query("SELECT word, definition, pronunciation, partofdpeech, gender FROM dictionary WHERE definition IS NOT NULL AND revision >= ?", [revision])
207+
cursor = dictionaryDB.query("SELECT word, translation, definition, example, pronunciation, partofdpeech, gender FROM dictionary WHERE definition IS NOT NULL AND revision >= ?", [revision])
212208

213209
while True:
214210
row = cursor.fetchone()
@@ -253,8 +249,8 @@ def main():
253249
parser.add_argument('-kindleDB', help="Kindle vocabulary db filename (default: vocab.db)", default="vocab.db")
254250
parser.add_argument('-dictionaryDB', help="Memrise dictionary db filename (default: memrise.db)", default="memrise.db")
255251
parser.add_argument('-output', help="Output file to import to memrise.com (default: memrise.txt)", default="memrise.txt")
256-
parser.add_argument('-revision', type=int, help="Revision to output. Not specfied (default): last, 0 - all ", default="-1")
257-
parser.add_argument('-debug', action='store_true', help="Enable debug ", default=False)
252+
parser.add_argument('-revision', type=int, help="Revision to output. Not specfied (default): last, 0 - all", default="-1")
253+
parser.add_argument('-debug', action='store_true', help="Enable debug", default=False)
258254

259255
args = parser.parse_args()
260256

0 commit comments

Comments
 (0)