Skip to content

Instantly share code, notes, and snippets.

@bigmeech
Last active September 2, 2015 08:18
Show Gist options
  • Save bigmeech/f3ea2ce62748cb92bc82 to your computer and use it in GitHub Desktop.
Save bigmeech/f3ea2ce62748cb92bc82 to your computer and use it in GitHub Desktop.
node greping
var exec = require('child_process').exec;
var httpClient = require('request');
var _ = require('underscore');
var fs = require('fs');
var download = function (uri, filename, onDownloadComplete) {
httpClient.head(uri, function (err, res, body) {
httpClient(uri)
.pipe(fs.createWriteStream("./razunaImages/" + filename))
.on('close', onDownloadComplete);
});
};
exec("grep -r razuna .", function (err, stdout, stderr) {
var url_matches = stdout.match(/(https|http):\/\/\w\d\.\w{9}\.\w{2,3}\/razuna-server-tui(\/[\w\d%]+)+[\w\d_%]+\.\w+\?(([\w\d%]+=)[%\w\d]+&*)+/g);
_.chain(url_matches)
//.uniq()
.forEach(function (url, index, array) {
var match = url.match(/\/img\/[A-Z0-9]+\/([\d\w\W]+)\?/);
var imageName = match[1];
console.log("Queued ", imageName, "for downloading....");
download(url, imageName, function(){ console.log(imageName, '....downoad complete'); });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment