Last active
August 29, 2015 14:00
-
-
Save redaktor/11404745 to your computer and use it in GitHub Desktop.
Revisions
-
redaktor revised this gist
May 2, 2014 . 1 changed file with 15 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ // 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 = []; @@ -22,24 +22,30 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'. 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; -
redaktor revised this gist
Apr 29, 2014 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -44,6 +44,13 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'. 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 ... }); -
redaktor revised this gist
Apr 29, 2014 . 1 changed file with 1 addition and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ var vendorToJSON = 'Canon'; var scraper = require('scraper'); var util = require('util'); scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.html', function(err, jQuery) { if (err) {throw err} var h2 = []; @@ -13,20 +14,15 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'. 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 = ''; if(tds[3].textContent.indexOf(' = ')>-1){ // '0 = Off, 1 = On (1), 2 = On (2)' @@ -48,7 +44,6 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'. trs,ta[i].table = null; delete ta[i].table; }); console.log(util.inspect(ta, false, null)); // ta is our OBJECT! Do something with ta. E.g. write to file ... }); -
redaktor revised this gist
Apr 29, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -48,5 +48,7 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'. trs,ta[i].table = null; delete ta[i].table; }); console.log(util.inspect(ta, false, null)); // ta is our OBJECT! Do something with ta. E.g. write to file ... }); -
redaktor revised this gist
Apr 29, 2014 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,9 +29,12 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'. console.log( i ); var val = ''; if(tds[3].textContent.indexOf(' = ')>-1){ // '0 = Off, 1 = On (1), 2 = On (2)' var vals = tds[3].textContent.trim().replace(/\n/g, '",').replace(/ = /g,':"'); val = { name:tds[1].textContent.trim(), values:'{"'+vals+'"}' } vals = null; } else if(tds[3].textContent.indexOf('-->')>-1){ val = { reference:tds[3].textContent.trim().replace(/__>/g, ""), name: tds[1].textContent.replace(/\n/g, ",")}; } else { val = tds[1].textContent.trim().replace(/\n/g, ","); } @@ -40,8 +43,9 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'. } } tds,val = null; }); trs,ta[i].table = null; delete ta[i].table; }); console.log( ta[0] ); -
redaktor created this gist
Apr 29, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html#CameraInfo5DmkII var vendorToJSON = 'Canon'; var scraper = require('scraper'); scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.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:{}}); }); console.log( h2.length ); console.log( ta.length ); //var map = {}; ta.forEach(function(t,i){ ta[i].name = h2[i]; var trs = jQuery('tr', t.table); if(i<5) console.log('trs', trs.length ); trs.each(function(j,tr) { if(j>0){ var tds = jQuery('td', tr); if(i<5) console.log('tds', tds.length ); if(tds.length==4){ console.log( i ); var val = ''; if(tds[3].textContent.indexOf(' = ')>-1){ val = { name:tds[1].textContent.trim(), values:tds[3].textContent.trim().replace(/\n/g, ",") } } else if(tds[3].textContent.indexOf('-->')>-1){ val = tds[3].textContent.trim().concat(tds[1].textContent).replace(/\n/g, ","); } else { val = tds[1].textContent.trim().replace(/\n/g, ","); } ta[i].fields[tds[0].textContent] = val; } } }); ta[i].table = null; delete ta[i].table; }); console.log( ta[0] ); });