Last active
November 28, 2015 15:41
-
-
Save cakenggt/5c598ef1389405c526d5 to your computer and use it in GitHub Desktop.
Duolingo Vocab Scraper
This file contains 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
var skillList = []; | |
var learningLanguage = duo.user.attributes.learning_language | |
var skills = duo.user.attributes.language_data[learningLanguage].skills.models; | |
skills.sort(function(a, b){ | |
if (a.attributes.coords_y == b.attributes.coords_y){ | |
return a.attributes.coords_x-b.attributes.coords_x; | |
} | |
else{ | |
return a.attributes.coords_y-b.attributes.coords_y; | |
} | |
}); | |
var complete = 0; | |
var available = 0; | |
var titleMap = {}; | |
for (var x = 0; x < skills.length; x++){ | |
var skill = skills[x]; | |
var url_title = skill.attributes.url_title; | |
titleMap[skill.attributes.title] = x; | |
if (!skill.attributes.locked){ | |
available++; | |
$.getJSON('https://www.duolingo.com/skills/'+learningLanguage+'/'+url_title, function(response){ | |
var wordList = []; | |
for (var y = 0; y < response.path.length-1; y++){ | |
var pathObj = response.path[y]; | |
wordList = wordList.concat(pathObj.words); | |
} | |
skillList[titleMap[response.title]]= {"title":response.title, "words":wordList}; | |
}) | |
.always(function(){ | |
complete++; | |
if (complete == available){ | |
for (var z = 0; z < skillList.length; z++){ | |
var result = skillList[z]; | |
console.log('Skill Name: ' + result.title); | |
for (var w = 0; w < result.words.length; w++){ | |
console.log(result.words[w]); | |
} | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment