Skip to content

Instantly share code, notes, and snippets.

@rom3r4
Forked from Loddan/iso639.js
Created November 23, 2013 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rom3r4/7617210 to your computer and use it in GitHub Desktop.
Save rom3r4/7617210 to your computer and use it in GitHub Desktop.
#!/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