@@ -35,9 +35,9 @@ def translate(self):
35
35
desc = definition = example = pronunciation = audiofileURL = None
36
36
37
37
try :
38
- desc = soup .find (attrs = {"class" : "trans" }).get_text ().strip (). capitalize ()
38
+ translation = soup .find (attrs = {"class" : "trans" }).get_text ().strip ()
39
39
except :
40
- desc = None
40
+ translation = None
41
41
42
42
try :
43
43
definition = soup .find (attrs = {"class" : "def" }).get_text ().strip ().capitalize ()
@@ -47,56 +47,50 @@ def translate(self):
47
47
try :
48
48
example = soup .find (attrs = {"title" : "Example" }).get_text ().strip ()
49
49
except :
50
- example = "N/A"
50
+ example = None
51
51
52
52
try :
53
53
pronunciation = soup .find (attrs = {"class" : "ipa" }).get_text ().strip ()
54
54
except :
55
- pronunciation = ""
55
+ pronunciation = None
56
56
57
57
try :
58
58
audiofileURL = soup .find (attrs = {"data-src-mp3" : True }).attrs ['data-src-mp3' ]
59
59
except :
60
60
audiofileURL = None
61
-
61
+
62
+ if (translation == None ):
63
+ translation = definition
64
+ definition = None
62
65
63
66
print ("\n \033 [1m%s:\033 [0m" % term )
64
- print ("\t >> %s. %s " % ( desc , definition ) )
67
+ print ("\t >> %s" % translation )
65
68
69
+ print ("\n [-] Definition:" )
70
+ print ("\t %s\n " % definition )
71
+
66
72
print ("\n [-] Example:" )
67
- print ("\t {example} \n " . format ( example = example ) )
73
+ print ("\t %s \n " % example )
68
74
69
75
print ("\n [-] Pronunciation:" )
70
- print ("\t {pronunciation} \n " . format ( pronunciation = pronunciation ) )
76
+ print ("\t %s \n " % pronunciation )
71
77
72
78
print ("\n [-] Audio URL:" )
73
- print ("\t {url} \n " . format ( url = audiofileURL ) )
79
+ print ("\t %s \n " % audiofileURL )
74
80
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
83
82
84
- self .audiofilePath = downloadAudioFile (audiofileURL , term )
85
-
86
- def __init__ (self , word , definition , pronunciation , partofdpeech , gender , audiofileURL , audiofilePath ):
87
- self .word = word
88
83
self .definition = definition
84
+ self .example = example
85
+
89
86
self .pronunciation = pronunciation
90
- self .partofdpeech = partofdpeech
91
- self .gender = gender
92
87
self .audiofileURL = audiofileURL
93
- self .audiofilePath = audiofilePath
94
88
95
- self .translate ()
96
-
89
+ self .audiofilePath = downloadAudioFile (audiofileURL , term )
97
90
98
91
def __init__ (self , word ):
99
92
self .word = word
93
+ self .translation = None
100
94
self .definition = None
101
95
self .pronunciation = None
102
96
self .partofdpeech = None
@@ -136,7 +130,7 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
136
130
dictionaryDB = DatabaseManager (dictionaryDBFilename )
137
131
138
132
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)" )
140
134
141
135
try :
142
136
revisions = dictionaryDB .query ("SELECT MAX(revision) FROM dictionary" )
@@ -167,10 +161,12 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
167
161
168
162
translated = Translation (word )
169
163
170
- dictionaryDB .query ("INSERT INTO dictionary VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ,
164
+ dictionaryDB .query ("INSERT INTO dictionary VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" ,
171
165
[
172
166
translated .word ,
167
+ translated .translation ,
173
168
translated .definition ,
169
+ translated .example ,
174
170
translated .pronunciation ,
175
171
translated .partofdpeech ,
176
172
translated .gender ,
@@ -179,7 +175,7 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
179
175
revision
180
176
] )
181
177
182
- if (translated .definition != None ):
178
+ if (translated .translation != None ):
183
179
newWords += 1
184
180
except sqlite3 .Error as e :
185
181
print ("Skipping.... %s" % e )
@@ -197,7 +193,7 @@ def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevi
197
193
198
194
outputMemrise (dictionaryDB , revision , outputFilename )
199
195
200
- dictionaryDB .query ("DELETE FROM dictionary WHERE word=?" , [ "retorted" ]);
196
+ # dictionaryDB.query("DELETE FROM dictionary WHERE word=?", [ "retorted" ]);
201
197
202
198
dictionaryDB .close ()
203
199
kindleDB .close ()
@@ -208,7 +204,7 @@ def outputMemrise(dictionaryDB, revision, outputFilename):
208
204
209
205
try :
210
206
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 ])
212
208
213
209
while True :
214
210
row = cursor .fetchone ()
@@ -253,8 +249,8 @@ def main():
253
249
parser .add_argument ('-kindleDB' , help = "Kindle vocabulary db filename (default: vocab.db)" , default = "vocab.db" )
254
250
parser .add_argument ('-dictionaryDB' , help = "Memrise dictionary db filename (default: memrise.db)" , default = "memrise.db" )
255
251
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 )
258
254
259
255
args = parser .parse_args ()
260
256
0 commit comments