-
-
Save extenlabs/4d2d9bdeb50af60232d3ad5555f1068a to your computer and use it in GitHub Desktop.
Export Memrise course words to CSV. There is also a Chrome Extension: https://chrome.google.com/webstore/detail/memrise-export/hcllgkpmoiolndnhmbdceffaidjmkoam
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Export Memrise course words to CSV (technically TSV, or "tab separated file", but it is effectively the same). | |
| 1. Log into Memrise. | |
| 2. Navigate to the course page you would like to export (e.g. https://app.memrise.com/course/2156672/german-random-01/). | |
| 3. Open the browser's Developer Console (https://support.airtable.com/hc/en-us/articles/232313848-How-to-open-the-developer-console) | |
| 4. Paste the below script into the console and hit enter. | |
| 5. After all pages have been loaded, copy and paste the final word list into spreadsheet. | |
| */ | |
| (() => { | |
| /** Returns a Promise of a list of all words in a course. */ | |
| function getWords(courseId, level=0) { | |
| if (level > 0) { | |
| console.log(`Loading Page ${level}...`) | |
| } | |
| const url = `${location.origin}/ajax/session/?course_id=${courseId}&level_index=${level + 1}&session_slug=preview` | |
| return fetch(url, { credentials: 'same-origin' }) | |
| // parse response | |
| .then(res => res.ok | |
| ? res.json() | |
| // map results | |
| .then(data => { | |
| const { name, num_things, num_levels } = data.session.course | |
| if (level === 0) { | |
| console.log(`Exporting ${num_things} words (${num_levels} pages) from "${name}"`) | |
| } | |
| return data.learnables.map(row => ({ | |
| original: row.item.value, | |
| translation: row.definition.value | |
| })) | |
| }) | |
| .then(words => { | |
| // RECURSION | |
| return getWords(courseId, level + 1) | |
| .then(words.concat.bind(words)) | |
| }) | |
| // print an error if they are not logged in | |
| : res.status > 400 ? res.text().then(text => { | |
| console.error(`Error (${res.status}): ${text}`) | |
| return [] | |
| }) | |
| : [] | |
| ) | |
| .catch(err => { | |
| console.error(err) | |
| return [] | |
| }) | |
| } | |
| // parse the course id | |
| const courseId = location.href.slice(30).match(/\d+/)[0] | |
| // get the words | |
| getWords(courseId).then(words => { | |
| if (words.length > 0) { | |
| const output = words.map(word => `${word.translation}\t${word.original}\n`).join('') | |
| console.log(output) | |
| } | |
| }) | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment