fahrplan_download.js: optimize

This commit is contained in:
Astro 2010-10-17 16:27:26 +02:00
parent 07d56d5da5
commit 832be75cda
1 changed files with 20 additions and 3 deletions

View File

@ -18,7 +18,7 @@ var outputDir = '.';
var baseDir = '/fahrplan';
var clients = [];
for(var i = 0; i < 8; i++)
for(var i = 0; i < 4; i++)
clients.push(HTTP.createClient(443, 'cccv.pentabarf.org', true));
function get(path, cb) {
@ -36,6 +36,13 @@ function get(path, cb) {
else
console.warn(res.statusCode + ': ' + path);
});
req.on('error', function(e) {
console.error(e.message);
// Retry:
process.nextTick(function() {
get(path, cb);
});
});
}
function base64(s) {
@ -183,13 +190,23 @@ Spider.prototype.see = function(path, from) {
case 'src':
that.see(v);
return manglePath(v);
case 'action':
return (v.indexOf('://') >= 0) ? v : 'https://cccv.pentabarf.org' + v;
default:
return v;
}
}
get(path, downloadXml(outPath, rewriteAttr));
} else
get(path, downloadTo(outPath));
} else {
// just binary download
try {
FS.statSync(outPath);
console.log('.. '+outPath);
} catch(e) {
// statSync() raised ENOENT?
get(path, downloadTo(outPath));
}
}
};
new Spider();