Skip to content

Instantly share code, notes, and snippets.

@andreafalzetti
Created June 1, 2019 22:25
Show Gist options
  • Save andreafalzetti/c95ae8a907ec949017333519214560c3 to your computer and use it in GitHub Desktop.
Save andreafalzetti/c95ae8a907ec949017333519214560c3 to your computer and use it in GitHub Desktop.
Lingoda Teaching Material Downloader in Node.js
/**
* Node.js Script to Download Lingoda Teaching Material
*/
const fs = require('fs');
const needle = require('needle');
const { promisify } = require('util');
const { stringify } = require('query-string');
const mkdir = require('mkdirp-promise');
const writeFileAsync = promisify(fs.writeFile);
const downloadLang = 'spanish'; // change this one
const lingodaUrl = 'https://www.lingoda.com';
const apiUrl = `${lingodaUrl}/en/api`;
const downloadFolder = './download';
const run = async () => {
await mkdir(downloadFolder);
const res = await needle(`${apiUrl}/modules`, { json: true });
const modules = res.body.data;
modules.forEach(async m => {
console.log(`[${m.name}] Downloading Modules`);
const params = stringify({
moduleId: m.id,
section: downloadLang
});
console.log(`[API_CALL] ${apiUrl}/learning-units?${params}`);
let resUnits = await needle(`${apiUrl}/learning-units?${params}`, {
json: true
});
if (!resUnits.body.included || !resUnits.body.included.lessons) {
console.log(`Skip Module ${m.name}`);
return;
}
const { lessons } = resUnits.body.included;
lessons.forEach(async lesson => {
const docUrl = `${lingodaUrl}${lesson.presentation}`;
console.log(`[Download] ${docUrl}`);
const doc = await needle(docUrl);
const titleSafe = lesson.title.replace(/ /g, '-');
const pdfName = `${lesson.label}-${titleSafe}.pdf`;
const destFolder = `${downloadFolder}/${m.name}`;
await mkdir(destFolder);
await writeFileAsync(`${destFolder}/${pdfName}`, doc.body);
});
});
};
run();
@27845Y4
Copy link

27845Y4 commented Jan 24, 2024

Hello! I've tried the code but it doesn't work. Do you have an updated version?

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