Skip to content

Instantly share code, notes, and snippets.

@raineorshine
Last active December 1, 2021 17:02
Show Gist options
  • Save raineorshine/68fab3b4b96f54b808a858217b83fe94 to your computer and use it in GitHub Desktop.
Save raineorshine/68fab3b4b96f54b808a858217b83fe94 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
/*
UPDATE: This is now a Chrome Extension: https://chrome.google.com/webstore/detail/memrise-export/hcllgkpmoiolndnhmbdceffaidjmkoam
Source Code: https://github.com/raineorshine/memrise-export
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)
}
})
})()
@raineorshine
Copy link
Author

@Yinyue93 Yay! I'm glad the new version works.

@AniruddhaHumane
Copy link

Hi, Is it possible to export mems too? Mnemonics I mean?

@raineorshine
Copy link
Author

@AniruddhaHumane I'm not sure, where can I find them in Memrise? I've only worked with the course page so far, in which the following data is available:

Course:

{
  "id": 2156672,
  "name": "German Random 01",
  "slug": "german-random-01",
  "url": "/course/2156672/german-random-01/",
  "description": "",
  "photo": "https://static.memrise.com/uploads/course_photos/19881832000190401135248.png",
  "photo_small": "https://static.memrise.com/img/100sqf/from/uploads/course_photos/19881832000190401135248.png",
  "photo_large": "https://static.memrise.com/img/400sqf/from/uploads/course_photos/19881832000190401135248.png",
  "num_things": 45,
  "num_levels": 2,
  "num_learners": 11,
  "source": {
    "id": 963,
    "slug": "english-us",
    "name": "English (US)",
    "photo": "https://static.memrise.com/uploads/category_photos/us_flag.png",
    "parent_id": 578,
    "index": 0,
    "language_code": "en-US"
  },
  "target": {
    "id": 4,
    "slug": "german-2",
    "name": "German",
    "photo": "https://static.memrise.com/uploads/language_photos/german.png",
    "parent_id": 879,
    "index": 1048,
    "language_code": "de"
  },
  "contains_sample_sentences": false,
  "is_memrise_course": false,
  "num_items_for_review": 0
}"

Words:

{
  "learnable_id": "14170871300354",
  "thing_id": 216230336,
  "item": {
    "kind": "text",
    "value": "immer",
    "label": "German",
    "always_show": false,
    "alternatives": [],
    "style": []
  },
  "definition": {
    "kind": "text",
    "value": "always",
    "label": "English",
    "always_show": false,
    "alternatives": [],
    "style": []
  },
  "confused_answers": [],
  "difficulty": "unknown"
}

@raineorshine
Copy link
Author

@AniruddhaHumane
Copy link

AniruddhaHumane commented Sep 9, 2020

great work @raineorshine! mnemonics are available in the community-made courses and they speed up the learning process a lot. Here's a link to one of the community-made courses that have mnemonics. Apparently I am not able to view them on the website but probably they show it when we start learning or reviewing. I couldn't find any *.jpg/jpeg/png in the JSON that is being parsed too.

@raineorshine
Copy link
Author

@AniruddhaHumane Thanks. I did find the internal API for mems, but it's not clear how we should export them since there are multiple mems per learning item. I invite you to join me in further discussion here: raineorshine/memrise-export#2.

@WiliTest
Copy link

WiliTest commented Apr 2, 2021

The script did not work for me on the console (for this course) but the Chrome Extension did (thank you!). It would be great to export all the mems, but only if it was possible to reimport them on another Memrise course (is it possible?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment