├── .gitignore
├── variables.py-example.py
├── uploadAudio.py
├── README.md
├── kindle2memrise.py
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | audio/*.mp3
2 | memrise.db
3 | memrise.txt
4 | vocab.db
5 | variables.py
6 | *.pyc
7 |
--------------------------------------------------------------------------------
/variables.py-example.py:
--------------------------------------------------------------------------------
1 | #
2 | # Rename the file to variables.py
3 | #
4 |
5 | # cookeis file exported from EditThisCookie chrome extension in format:
6 | # cookies = [
7 | # {
8 | # "domain": ".memrise.com",
9 | # "expirationDate": 1541160876,
10 | # "hostOnly": false,
11 | # "httpOnly": false,
12 | # "name": "ajs_anonymous_id",
13 | # "path": "/",
14 | # "sameSite": "no_restriction",
15 | # "secure": false,
16 | # "session": false,
17 | # "storeId": "0",
18 | # "value": "xxxxxx",
19 | # "id": 1
20 | #},
21 | #
22 | # Manual changes in the file:
23 | # - add "cookies = " in begginning of the 1st line
24 | # - change true -> True
25 | # - change false -> False
26 |
27 | cookies = [
28 | {
29 | "domain": ".memrise.com",
30 | "expirationDate": 1541160840,
31 | "hostOnly": False,
32 | "httpOnly": False,
33 | "name": "ajs_anonymous_id",
34 | "path": "/",
35 | "sameSite": "no_restriction",
36 | "secure": False,
37 | "session": False,
38 | "storeId": "0",
39 | "value": "xxxx",
40 | "id": 1
41 | },
42 | {
43 | "domain": ".memrise.com",
44 | "expirationDate": 1541449140,
45 | "hostOnly": False,
46 | "httpOnly": False,
47 | "name": "ajs_group_id",
48 | "path": "/",
49 | "sameSite": "no_restriction",
50 | "secure": False,
51 | "session": False,
52 | "storeId": "0",
53 | "value": "null",
54 | "id": 2
55 | },
56 | {
57 | "domain": ".memrise.com",
58 | "expirationDate": 1541449140,
59 | "hostOnly": False,
60 | "httpOnly": False,
61 | "name": "ajs_user_id",
62 | "path": "/",
63 | "sameSite": "no_restriction",
64 | "secure": False,
65 | "session": False,
66 | "storeId": "0",
67 | "value": "23978049",
68 | "id": 3
69 | },
70 | {
71 | "domain": ".memrise.com",
72 | "expirationDate": 1512492840,
73 | "hostOnly": False,
74 | "httpOnly": False,
75 | "name": "mp_super_properties",
76 | "path": "/",
77 | "sameSite": "no_restriction",
78 | "secure": False,
79 | "session": False,
80 | "storeId": "0",
81 | "value": "xxxxx",
82 | "id": 4
83 | },
84 | {
85 | "domain": "www.memrise.com",
86 | "hostOnly": True,
87 | "httpOnly": False,
88 | "name": "csrftoken",
89 | "path": "/",
90 | "sameSite": "no_restriction",
91 | "secure": False,
92 | "session": True,
93 | "storeId": "0",
94 | "value": "xxx",
95 | "id": 5
96 | },
97 | {
98 | "domain": "www.memrise.com",
99 | "hostOnly": True,
100 | "httpOnly": False,
101 | "name": "i18next",
102 | "path": "/",
103 | "sameSite": "no_restriction",
104 | "secure": False,
105 | "session": True,
106 | "storeId": "0",
107 | "value": "en",
108 | "id": 6
109 | },
110 | {
111 | "domain": "www.memrise.com",
112 | "expirationDate": 1514745900,
113 | "hostOnly": True,
114 | "httpOnly": True,
115 | "name": "sessionid",
116 | "path": "/",
117 | "sameSite": "no_restriction",
118 | "secure": False,
119 | "session": False,
120 | "storeId": "0",
121 | "value": "xxx",
122 | "id": 7
123 | }
124 | ]
--------------------------------------------------------------------------------
/uploadAudio.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import os
4 | import re
5 | import sys
6 | import argparse
7 | import sqlite3
8 | import json
9 |
10 | from urllib.request import urlopen
11 | from urllib.request import urlretrieve
12 |
13 | import requests
14 |
15 | from bs4 import BeautifulSoup
16 |
17 | # cookeis file exported from EditThisCookie chrome extension in format:
18 | # cookies = [
19 | # {
20 | # "domain": ".memrise.com",
21 | # "expirationDate": 1541160876,
22 | # "hostOnly": false,
23 | # "httpOnly": false,
24 | # "name": "ajs_anonymous_id",
25 | # "path": "/",
26 | # "sameSite": "no_restriction",
27 | # "secure": false,
28 | # "session": false,
29 | # "storeId": "0",
30 | # "value": "xxxxxx",
31 | # "id": 1
32 | #},
33 | #
34 | # Manual changes in the file:
35 | # - add "cookies = " in begginning of the 1st line
36 | # - change true -> True
37 | # - change false -> False
38 |
39 | from variables import cookies
40 |
41 | MEMRISE_ENDPOINT = "https://www.memrise.com/course/"
42 | MEMRISE_LEVEL_ENDPOINT = "https://www.memrise.com/ajax/level/editing_html/?level_id="
43 | MEMRISE_UPLOAD_ENDPOINT = "https://www.memrise.com/ajax/thing/cell/upload_file/"
44 |
45 | class DatabaseManager(object):
46 | def __init__(self, db):
47 | self.conn = sqlite3.connect(db)
48 | self.conn.execute('pragma foreign_keys = on')
49 | self.conn.commit()
50 |
51 | self.cur = self.conn.cursor()
52 |
53 | def query(self, *arg):
54 | self.cur.execute(*arg)
55 | self.conn.commit()
56 | return self.cur
57 |
58 | def close(self):
59 | self.conn.close()
60 |
61 | def __del__(self):
62 | self.conn.close()
63 |
64 | class CookiesJar(object):
65 | def __init__(self):
66 | print("Initialising cookies jar")
67 |
68 | self.cookies = requests.cookies.RequestsCookieJar()
69 |
70 | for cookie in cookies:
71 | self.cookies.set(cookie['name'], cookie['value'], domain=cookie['domain'], path=cookie['path'])
72 |
73 | def getCookieValue(self, name):
74 | for cookie in cookies:
75 | if(cookie['name'] == name):
76 | return cookie['value']
77 | return None
78 |
79 | def getAudioFilename(dictionaryDB, word):
80 | try:
81 | audioFilename = dictionaryDB.query("SELECT audiofilePath FROM dictionary WHERE word=? AND audiofilePath is not null", [word]).fetchone()[0]
82 | except:
83 | print("Audio file for %s not found!" % word)
84 | return None
85 |
86 | return audioFilename
87 |
88 | def uploadFileToServer(thing_id, cell_id, memriseEditURL, filename, jar):
89 | files = {'f': ('whatever.mp3', open(filename, 'rb'), 'audio/mp3')}
90 |
91 | form_data = {
92 | "thing_id": thing_id,
93 | "cell_id": cell_id,
94 | "cell_type": "column",
95 | "csrfmiddlewaretoken": jar.getCookieValue('csrftoken')}
96 |
97 | headers = {
98 | "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0",
99 | "referer": memriseEditURL}
100 |
101 | r = requests.post(MEMRISE_UPLOAD_ENDPOINT, files=files, cookies=jar.cookies, headers=headers, data=form_data, timeout=60)
102 |
103 | if not r.status_code == requests.codes.ok:
104 | print("Result code: %d" % r.status_code)
105 |
106 | def uploadAudio(dictionaryDBFilename, revision, course, debug):
107 | jar = CookiesJar()
108 |
109 | print("Opening dictionaryDB: %s" % dictionaryDBFilename)
110 | dictionaryDB = DatabaseManager(dictionaryDBFilename)
111 |
112 | print("Opening base URL: %s" % (MEMRISE_ENDPOINT + course))
113 | memrise = requests.get(MEMRISE_ENDPOINT + course, cookies=jar.cookies)
114 |
115 | memriseEditURL = memrise.url + "edit"
116 | print("Opening edit URL: %s" % memriseEditURL)
117 | memriseEdit = requests.get(memriseEditURL, cookies=jar.cookies)
118 |
119 | soup = BeautifulSoup(memriseEdit.content, 'html.parser')
120 |
121 | try:
122 | levelId = soup.find(attrs={"data-level-id": True}).attrs['data-level-id']
123 | except:
124 | passs
125 |
126 | memriseLevelURL = MEMRISE_LEVEL_ENDPOINT + levelId
127 |
128 | print("Opening level URL: %s" % memriseLevelURL)
129 |
130 | memriseLevel = requests.get(memriseLevelURL, cookies=jar.cookies)
131 |
132 | thingsJson = json.loads(memriseLevel.content)
133 |
134 | thingsHtml = re.sub(r'\n', '', thingsJson['rendered'])
135 |
136 | soup = BeautifulSoup(thingsHtml, 'html.parser')
137 | things = soup.find_all(attrs={"class": "thing"})
138 |
139 | total = 0
140 |
141 | for thing in things:
142 | soup = BeautifulSoup(str(thing), 'html.parser')
143 |
144 | thingId = soup.find(attrs={"class": "thing", "data-thing-id": True }).attrs['data-thing-id']
145 |
146 | # Hardocoded column IDs
147 | # 1 - English word
148 | # 3 - Audios
149 |
150 | word = soup.find(attrs={"data-cell-type": "column", "data-key": "1" }).find(attrs={"class": "text"}).get_text().strip()
151 | audioCellId = 3
152 |
153 | hasAudioFile = soup.find(attrs={"data-cell-type": "column", "data-key": "3" }).find(string=re.compile("no audio file"))
154 |
155 | if(hasAudioFile == None):
156 | continue
157 |
158 | print(word)
159 |
160 | audioFilename = getAudioFilename(dictionaryDB, word)
161 | uploadFileToServer(thingId, audioCellId, memriseEditURL, audioFilename, jar)
162 |
163 | total += 1
164 |
165 | print("Total numner: %d" % total)
166 |
167 | dictionaryDB.close()
168 |
169 |
170 | def usage(parser):
171 | parser.print_help()
172 |
173 | def main():
174 | parser = argparse.ArgumentParser()
175 |
176 | parser.add_argument('-dictionaryDB', help="Memrise dictionary db filename (default: memrise.db)", default="memrise.db")
177 | parser.add_argument('-revision', type=int, help="Revision to output. Not specfied (default): last, 0 - all", default="-1")
178 | parser.add_argument('-course', help="Memrise course ID", default="1722628")
179 | parser.add_argument('-debug', action='store_true', help="Enable debug ", default=False)
180 |
181 | args = parser.parse_args()
182 |
183 | uploadAudio(
184 | args.dictionaryDB,
185 | args.revision,
186 | args.course,
187 | args.debug
188 | )
189 |
190 |
191 | if __name__ == "__main__":
192 | main()
193 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # kindle-to-memrise
2 |
3 | ## Introduction
4 |
5 | A script to pull Kindle Vocabulary Builder DB and convert into Memrise course (`kindle2memrise.py`)
6 |
7 | Another script (`uploadAudio.py`) can upload audio mp3s to the course.
8 |
9 | The latest Kindle Paperwhite (second generation) offers the Vocabulary Builder feature. With Vocabulary Builder, you can look up words with the dictionary and memorize their definitions.
10 |
11 | For my self-education I use [http://memrise.com/](http://memrise.com/) (both on my phone and desktop PC). I thought it would be great to pull words which I've checkded when reading English books on my Kindle and push them into my Memrise course.
12 |
13 | ## How does it work?
14 |
15 | ### Create course (`kindle2memrise.py`)
16 |
17 | 1. The script reads through the vocab.db to look for all Engligh words (in table WORDS).
18 | 2. Each of the words (aka _stems_) is used for a definition lookup in the [Cambridge Dictionary](https://dictionary.cambridge.org/)
19 | 3. Retreve word definitions, usage example, pronounciation, audio mp3 and insert into a new SQLite database `memrise.db` (the mp3 is written to the disk only, folder `audio`)
20 | 4. Each new word is written to a text file, in a format suitable for bulk words import into Memrise.
21 |
22 | ### Upload audio files (`uploadAudio.py`)
23 |
24 | 1. Get list of all words from the course
25 | 2. If a word still does not have any audio file...
26 | 3. ...retireves mp3 filename from the DB created in the 1st stage
27 | 4. Uploads the mp3 to Memrise
28 |
29 | ## Pre-requisties
30 |
31 | * Kindle Paperwhite (or newer)
32 | * `vocab.db` file (retrieved from your Kindle, from `/Volumes/Kindle/system/vocabulary/`)
33 | * python 3
34 | * BeautifulSoup
35 | * requests
36 |
37 | ## References
38 |
39 | I heavily sourced from two GitHub projects:
40 |
41 | * [cambridge-cli](https://github.com/pasternak/cambridge-cli)
42 | * [bulk-audio-upload](https://github.com/DrewSSP/bulk-audio-upload)
43 |
44 | Also, I was using these documents and toold:
45 |
46 | * [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)
47 | * [requests](http://requests.readthedocs.io/en/master/user/quickstart/)
48 | * [Edit This Cookie!](https://chrome.google.com/webstore/detail/editthiscookie/)
49 |
50 | And finally, my webpage:
51 |
52 | * [http://jhartman.pl](http://jhartman.pl/2017/11/05/kindle-vocabulary-builder-into-memrise/)
53 |
54 |
55 | ## ToDOs
56 |
57 | * Parametrize hardcoded things - especially language pair English-Polish
58 | * Upload Audio files with prononciation
59 |
60 | # Usage `kindle2memrise.py`
61 |
62 | ## DB conversion
63 |
64 | ```
65 | MBP:kindle-to-memrise jhartman$ ./kindle2memrise.py -h
66 | usage: kindle2memrise.py [-h] [-kindleDB KINDLEDB]
67 | [-dictionaryDB DICTIONARYDB] [-output OUTPUT]
68 | [-revision REVISION] [-debug]
69 |
70 | optional arguments:
71 | -h, --help show this help message and exit
72 | -kindleDB KINDLEDB Kindle vocabulary db filename (default: vocab.db)
73 | -dictionaryDB DICTIONARYDB
74 | Memrise dictionary db filename (default: memrise.db)
75 | -output OUTPUT Output file to import to memrise.com (default:
76 | memrise.txt)
77 | -revision REVISION Revision to output. Not specfied (default): last, 0 -
78 | all
79 | -debug Enable debug
80 | ```
81 |
82 | At minimum, the tool does not require any parameters, it will search for `vocab.db` in the current folder and will write output files into the same, current folder.
83 |
84 | Pay your special attention to `memrise.txt` which has been generated:
85 |
86 | ```
87 | MBP:kindle-to-memrise jhartman$ tail memrise.txt
88 | mere Sam. Used to emphasize that something is not large or important. Example: It costs a mere twenty dollars. mɪər
89 | thinning Rozcieńczać, rozrzedzać. To make a substance less thick, often by adding a liquid to it. Example: N/A θɪn
90 | carnivore Zwierzę mięsożerne. An animal that eats meat. Example: N/A ˈkɑːnɪvɔːr
91 | embrace Obejmować (się). If you embrace someone, you put your arms around them, and if two people embrace, they put their arms around each other.. Example: We are always eager to embrace the latest technology. ɪmˈbreɪs
92 | ```
93 | This is the file, which will be used for [bulk word add](http://feedback.memrise.com/knowledgebase/articles/525095-add-words-to-my-course-or-upload-words-from-a-spre) into your Course.
94 |
95 | ## Bulk word add
96 |
97 | Create a new Course.
98 |
99 | In the course, add two new columns: **Definition** and **Example**.
100 |
101 | Edit settings for both of new columns, edit attributes:
102 |
103 | * *Definition* - edit settings:
104 | * *Display* - only _Show after tests_ is selected
105 | * *Testing* - all options unselected
106 | * *Example* - edit settings:
107 | * *Display* - all options unselected
108 | * *Testing* - only _Tapping Tests Enabled_ is selected
109 |
110 | Go to your Course, press Edit and in the Advanced options, look for _Bulk add words_:
111 |
112 | 
113 |
114 | Open `memrise.txt` in an editor (e.g. Notepad), select all, copy it and paste into Memrise Bulk Add form then press _Add_:
115 |
116 | 
117 |
118 | # Usage `uploadAudio.py`
119 |
120 | ```
121 | usage: uploadAudio.py [-h] [-dictionaryDB DICTIONARYDB] [-revision REVISION]
122 | [-course COURSE] [-debug]
123 |
124 | optional arguments:
125 | -h, --help show this help message and exit
126 | -dictionaryDB DICTIONARYDB
127 | Memrise dictionary db filename (default: memrise.db)
128 | -revision REVISION Revision to output. Not specfied (default): last, 0 -
129 | all
130 | -course COURSE Memrise course ID
131 | -debug Enable debug
132 | ```
133 |
134 | 1. Login to the memrise and export cookies (using Chrome [Edit This Cookie!](https://chrome.google.com/webstore/detail/editthiscookie/) extension)
135 | 2. TBD
136 |
137 | # Support
138 |
139 | Your support on Buy Me a Coffee is invaluable, motivating me to continue crafting bytes that matters – thank you sincerely 👍
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/kindle2memrise.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import os
4 | import re
5 | import sys
6 | import argparse
7 | import sqlite3
8 |
9 | from urllib.request import urlopen
10 | from urllib.request import urlretrieve
11 |
12 | from bs4 import BeautifulSoup
13 |
14 |
15 | CAMBRIDGE_ENDPOINT = \
16 | "https://dictionary.cambridge.org/search/english-polish/direct/?q="
17 |
18 | # https://github.com/pasternak/cambridge-cli/blob/master/cambridge-cli.py
19 | # https://github.com/DrewSSP/bulk-audio-upload
20 |
21 | class Translation(object):
22 | def translate(self):
23 | term = re.sub(r"\s", "-", self.word)
24 |
25 | try:
26 | cdict = urlopen(CAMBRIDGE_ENDPOINT + term)
27 | if (cdict.getcode() != 200):
28 | print("Error")
29 | return
30 | except:
31 | return
32 |
33 | soup = BeautifulSoup(cdict, 'html.parser')
34 |
35 | desc = definition = example = pronunciation = audiofileURL = None
36 |
37 | try:
38 | translation = soup.find(attrs={"class": "trans"}).get_text().strip()
39 | except:
40 | translation = None
41 |
42 | try:
43 | definition = soup.find(attrs={"class": "def"}).get_text().strip().capitalize()
44 | except:
45 | definition = None
46 |
47 | try:
48 | example = soup.find(attrs={"title": "Example"}).get_text().strip()
49 | except:
50 | example = None
51 |
52 | try:
53 | pronunciation = soup.find(attrs={"class": "ipa"}).get_text().strip()
54 | except:
55 | pronunciation = None
56 |
57 | try:
58 | audiofileURL = soup.find(attrs={"data-src-mp3": True}).attrs['data-src-mp3']
59 | except:
60 | audiofileURL = None
61 |
62 | if(translation == None):
63 | translation = definition
64 | definition = None
65 |
66 | print("\n\033[1m%s:\033[0m" % term)
67 | print("\t>> %s" % translation )
68 |
69 | print("\n[-] Definition:")
70 | print("\t%s\n" % definition)
71 |
72 | print("\n[-] Example:")
73 | print("\t%s\n" % example)
74 |
75 | print("\n[-] Pronunciation:")
76 | print("\t%s\n" % pronunciation)
77 |
78 | print("\n[-] Audio URL:")
79 | print("\t%s\n" % audiofileURL)
80 |
81 | self.translation = translation
82 |
83 | self.definition = definition
84 | self.example = example
85 |
86 | self.pronunciation = pronunciation
87 | self.audiofileURL = audiofileURL
88 |
89 | self.audiofilePath = downloadAudioFile(audiofileURL, term)
90 |
91 | def __init__(self, word):
92 | self.word = word
93 | self.translation = None
94 | self.definition = None
95 | self.pronunciation = None
96 | self.partofdpeech = None
97 | self.gender = None
98 | self.audiofileURL = None
99 | self.audiofilePath = None
100 |
101 | self.translate()
102 |
103 |
104 | class DatabaseManager(object):
105 | def __init__(self, db):
106 | self.conn = sqlite3.connect(db)
107 | self.conn.execute('pragma foreign_keys = on')
108 | self.conn.commit()
109 |
110 | self.cur = self.conn.cursor()
111 |
112 | def query(self, *arg):
113 | self.cur.execute(*arg)
114 | self.conn.commit()
115 | return self.cur
116 |
117 | def close(self):
118 | self.conn.close()
119 |
120 | def __del__(self):
121 | self.conn.close()
122 |
123 | def translate(kindleDBFilename, dictionaryDBFilename, outputFilename, outputRevision, debug):
124 | newWords = 0
125 |
126 | print("Opening kindleDB: %s" % kindleDBFilename)
127 | kindleDB = DatabaseManager(kindleDBFilename)
128 |
129 | print("Opening dictionaryDB: %s" % dictionaryDBFilename)
130 | dictionaryDB = DatabaseManager(dictionaryDBFilename)
131 |
132 |
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)")
134 |
135 | try:
136 | revisions = dictionaryDB.query("SELECT MAX(revision) FROM dictionary")
137 | revision = revisions.fetchone()[0] + 1
138 | except:
139 | revision = 1
140 |
141 | rows = kindleDB.query("SELECT stem FROM WORDS WHERE lang='en'")
142 |
143 | while True:
144 | row = rows.fetchone()
145 |
146 | if row == None:
147 | break
148 |
149 | # stem (i.e. word)
150 | word = row[0];
151 |
152 | if(debug):
153 | print("Found in KindleDB: %s" % word)
154 |
155 | alreadyInDB = dictionaryDB.query("SELECT COUNT(*) FROM dictionary where word=?", [word])
156 |
157 | if(alreadyInDB.fetchone()[0] > 0):
158 | continue;
159 |
160 | try:
161 |
162 | translated = Translation(word)
163 |
164 | dictionaryDB.query("INSERT INTO dictionary VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
165 | [
166 | translated.word,
167 | translated.translation,
168 | translated.definition,
169 | translated.example,
170 | translated.pronunciation,
171 | translated.partofdpeech,
172 | translated.gender,
173 | translated.audiofileURL,
174 | translated.audiofilePath,
175 | revision
176 | ] )
177 |
178 | if(translated.translation != None):
179 | newWords += 1
180 | except sqlite3.Error as e:
181 | print("Skipping.... %s" % e)
182 |
183 | # If no new words, fallback to the previous revision)
184 |
185 | print("Number of new words: %d" % newWords)
186 |
187 | #if(newWords == 0):
188 | # revision -= 1
189 |
190 | if(outputRevision == 0):
191 | print
192 | revision = 0
193 |
194 | outputMemrise(dictionaryDB, revision, outputFilename)
195 |
196 | # dictionaryDB.query("DELETE FROM dictionary WHERE word=?", [ "retorted" ]);
197 |
198 | dictionaryDB.close()
199 | kindleDB.close()
200 |
201 | def outputMemrise(dictionaryDB, revision, outputFilename):
202 | print ("Writting output memrise file: %s" % outputFilename)
203 | print ("Revision (or greater) %d " % revision)
204 |
205 | try:
206 | with open(outputFilename, 'w') as f:
207 | cursor = dictionaryDB.query("SELECT word, translation, definition, example, pronunciation, partofdpeech, gender FROM dictionary WHERE definition IS NOT NULL AND revision >= ?", [revision])
208 |
209 | while True:
210 | row = cursor.fetchone()
211 |
212 | if(row == None):
213 | break
214 |
215 | outputLine = ""
216 |
217 | for i in row:
218 | if(i == None):
219 | outputLine += "\t"
220 | else:
221 | outputLine += i + "\t"
222 |
223 | print(outputLine, file=f)
224 | except Error as e:
225 | print ("Error writting the file" + e)
226 |
227 | def downloadAudioFile(URL, filename):
228 | directory = 'audio'
229 |
230 | filename = filename.replace(" ", "_")
231 |
232 | if not os.path.exists(directory):
233 | os.makedirs(directory)
234 |
235 | try:
236 | filename = os.path.join(directory, filename + '.mp3')
237 | urlretrieve(URL, filename)
238 | except:
239 | filename = None
240 |
241 | return filename
242 |
243 | def usage(parser):
244 | parser.print_help()
245 |
246 | def main():
247 | parser = argparse.ArgumentParser()
248 |
249 | parser.add_argument('-kindleDB', help="Kindle vocabulary db filename (default: vocab.db)", default="vocab.db")
250 | parser.add_argument('-dictionaryDB', help="Memrise dictionary db filename (default: memrise.db)", default="memrise.db")
251 | parser.add_argument('-output', help="Output file to import to memrise.com (default: memrise.txt)", default="memrise.txt")
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)
254 |
255 | args = parser.parse_args()
256 |
257 | translate(
258 | args.kindleDB,
259 | args.dictionaryDB,
260 | args.output,
261 | args.revision,
262 | args.debug
263 | )
264 |
265 |
266 | if __name__ == "__main__":
267 | main()
268 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------