Skip to content

Instantly share code, notes, and snippets.

@redaktor
Last active August 29, 2015 14:00
Show Gist options
  • Save redaktor/11404745 to your computer and use it in GitHub Desktop.
Save redaktor/11404745 to your computer and use it in GitHub Desktop.
requires node.js scraper, very experimental, gives you http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ as JSON
// http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html#CameraInfo5DmkII
var vendorToJSON = 'Nikon';
var scraper = require('scraper');
var util = require('util');
scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'Custom.html', function(err, jQuery) {
if (err) {throw err}
var h2 = [];
var ta = [];
jQuery('h2').each(function() {
h2.push(jQuery(this).text().trim());
});
jQuery('blockquote table.inner').each(function() {
ta.push({table:this, name:'', fields:{}});
});
//var map = {};
ta.forEach(function(t,i){
ta[i].name = h2[i];
var trs = jQuery('tr', t.table);
trs.each(function(j,tr) {
if(j>0){
var tds = jQuery('td', tr);
if(tds.length==4){
var val = '';
var str = (tds[3].textContent.trim().substr(0,1)=='[' && tds[3].textContent.trim().indexOf(']')>-1) ? tds[3].textContent.split(']')[1].trim() : tds[3].textContent.trim();
var vStr = tds[1].textContent.trim();
if(str.indexOf(' = ')>-1){
// '0 = Off, 1 = On (1), 2 = On (2)'
var vals = str.replace(/\n/g, '",').replace(/ = /g,':"');
val = { name:vStr, val:'{'+vals+'"}' }
vals = null;
} else if(str.indexOf('-->')>-1){
val = { ref:str.replace(/-->/g, "") };
} else {
val = vStr.replace(/\n/g, ",");
}
ta[i].fields[tds[0].textContent] = val;
val,str,vStr = null;
}
tds = null;
}
});
trs,ta[i].table = null;
delete ta[i].table;
});
var tmpTa = ta;
var ta = {};
tmpTa.forEach(function(t,i){
var n = t.name;
delete t.name;
ta[n] = t;
})
console.log(util.inspect(ta, false, null));
// ta is our OBJECT! Do something with ta. E.g. write to file ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment