From 832be75cdac40fd1d8e8c6624d48481c933ef971 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 17 Oct 2010 16:27:26 +0200 Subject: [PATCH] fahrplan_download.js: optimize --- scripts/fahrplan_download.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/fahrplan_download.js b/scripts/fahrplan_download.js index 84be71781..71a60748f 100755 --- a/scripts/fahrplan_download.js +++ b/scripts/fahrplan_download.js @@ -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();