-
-
Save NickTaporuk/a07566e1ec2d187c2273 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
var jsdom = require('jsdom'); | |
var wikipedia = 'http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes'; | |
var jquery = 'http://code.jquery.com/jquery.js'; | |
jsdom.env(wikipedia, [jquery], function (errors, window) { | |
var $ = window.$; | |
var tds = $('table[class="wikitable sortable"] > tr > td'); | |
if (tds.size() % 10 != 0) { | |
throw new Error('Ehhh something went terribly wrong'); | |
} | |
var languages = {}; | |
for (var i = 0, s = tds.size(); i < s; i += 10) { | |
var family = $(tds[i+1]).text(); | |
var name = $(tds[i+2]).text(); | |
var nativeName = $(tds[i+3]).text(); | |
var alpha1 = $(tds[i+4]).text(); | |
var alpha2t = $(tds[i+5]).text(); | |
var alpha2b = $(tds[i+6]).text(); | |
var alpha3 = $(tds[i+7]).text().split(/\s+/)[0];; | |
var alpha6 = $(tds[i+8]).text(); | |
languages[alpha1] = { | |
family : family, | |
name : name, | |
nativeName : nativeName, | |
}; | |
} | |
console.log('/* ISO 639-1 Codes'); | |
console.log(' * https://gist.github.com/4075450'); | |
console.log(' *', wikipedia); | |
console.log(' */'); | |
console.log(JSON.stringify(languages, null, 2)); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment