| OLD | NEW |
| (Empty) |
| 1 /** | |
| 2 * Uses a Google Custom Search Engine to find pages on | |
| 3 * developer.mozilla.org that appear to match types from the Webkit IDL | |
| 4 */ | |
| 5 var https = require('https'); | |
| 6 var fs = require('fs'); | |
| 7 | |
| 8 var domTypes = JSON.parse(fs.readFileSync('data/domTypes.json', 'utf8')); | |
| 9 | |
| 10 try { | |
| 11 fs.mkdirSync('output'); | |
| 12 fs.mkdirSync('output/search'); | |
| 13 } catch (e) { | |
| 14 // It doesn't matter if the directories already exist. | |
| 15 } | |
| 16 | |
| 17 function searchForType(type) { | |
| 18 // Strip off WebKit specific prefixes from type names to increase the chances | |
| 19 // of getting matches on developer.mozilla.org. | |
| 20 var shortType = type.replace(/^WebKit/, ""); | |
| 21 | |
| 22 // We use a Google Custom Search Engine provisioned for 10,000 API based | |
| 23 // queries per day that limits search results to developer.mozilla.org. | |
| 24 // You shouldn't need to, but if you want to create your own Google Custom | |
| 25 // Search Engine, visit http://www.google.com/cse/ | |
| 26 var options = { | |
| 27 host: 'www.googleapis.com', | |
| 28 path: '/customsearch/v1?key=AIzaSyDN1RhE5FafLzLfErGpoYhHlLHeyEkxTkM&' + | |
| 29 'cx=017193972565947830266:wpqsk6dy6ee&num=5&q=' + shortType, | |
| 30 port: 443, | |
| 31 method: 'GET' | |
| 32 }; | |
| 33 | |
| 34 var req = https.request(options, function(res) { | |
| 35 res.setEncoding('utf8'); | |
| 36 var data = ''; | |
| 37 res.on('data', function(d) { | |
| 38 data += d; | |
| 39 }); | |
| 40 var onClose = function(e) { | |
| 41 fs.writeFile("output/search/" + type + ".json", data, function(err) { | |
| 42 if (err) throw err; | |
| 43 console.log('Done searching for ' + type); | |
| 44 }); | |
| 45 } | |
| 46 res.on('close', onClose); | |
| 47 res.on('end', onClose); | |
| 48 }); | |
| 49 req.end(); | |
| 50 | |
| 51 req.on('error', function(e) { | |
| 52 console.error(e); | |
| 53 }); | |
| 54 } | |
| 55 | |
| 56 for (var i = 0; i < domTypes.length; i++) { | |
| 57 searchForType(domTypes[i]); | |
| 58 } | |
| OLD | NEW |