more sleeps...

This commit is contained in:
Sebastian Hugentobler 2020-12-23 23:35:45 +01:00
parent d3f6aeb62f
commit 5104bf7e2d
Signed by: shu
GPG Key ID: BB32CF3CA052C2F0
3 changed files with 14 additions and 15 deletions

17
nzz.js
View File

@ -48,7 +48,7 @@ function sleep(ms) {
* @param {fs.PathLike} outDir Final destination directory. * @param {fs.PathLike} outDir Final destination directory.
* @param {Date} date Date of the issue. * @param {Date} date Date of the issue.
*/ */
async function moveDownload(tmpDir, outDir, date) { function moveDownload(tmpDir, outDir, date) {
return new Promise(resolve => { return new Promise(resolve => {
let needsOffset = false; let needsOffset = false;
@ -60,20 +60,16 @@ async function moveDownload(tmpDir, outDir, date) {
let srcFile = path.join(tmpDir, `Gesamtausgabe_NZZ_-_Neue_Zürcher_Zeitung_${date.isoDate()}.pdf`); let srcFile = path.join(tmpDir, `Gesamtausgabe_NZZ_-_Neue_Zürcher_Zeitung_${date.isoDate()}.pdf`);
fs.watchFile(srcFile, () => {
if (fs.existsSync(srcFile)) {
fs.unwatchFile(srcFile);
if (needsOffset) { if (needsOffset) {
date = date.addDays(1); date = date.addDays(1);
} }
if (!fs.existsSync(srcFile)) {
setTimeout(() => moveDownload(tmpDir, outDir, date), 5000);
}
let destFile = path.join(outDir, `${date.isoDate()}.pdf`); let destFile = path.join(outDir, `${date.isoDate()}.pdf`);
fs.copyFileSync(srcFile, destFile); fs.copyFileSync(srcFile, destFile);
resolve();
}
});
}); });
} }
@ -93,6 +89,7 @@ async function enterDate(driver, date) {
let endDate = await driver.wait(until.elementLocated(By.css('input.fup-s-date-end')), WAIT_TIMEOUT, TIMEOUT_MSG, RETRY_DELAY); let endDate = await driver.wait(until.elementLocated(By.css('input.fup-s-date-end')), WAIT_TIMEOUT, TIMEOUT_MSG, RETRY_DELAY);
await endDate.clear(); await endDate.clear();
await endDate.sendKeys(dateString + Key.ENTER); await endDate.sendKeys(dateString + Key.ENTER);
await sleep(500);
} }
/** /**
@ -156,9 +153,11 @@ async function findIssues(driver, from, to, tmpDir, outDir) {
try { try {
let articles = await driver.wait(until.elementsLocated(By.css('.fup-archive-result-item-article-title')), SEARCH_WAIT_TIMEOUT, SEARCH_TIMEOUT_MSG, RETRY_DELAY); let articles = await driver.wait(until.elementsLocated(By.css('.fup-archive-result-item-article-title')), SEARCH_WAIT_TIMEOUT, SEARCH_TIMEOUT_MSG, RETRY_DELAY);
await articles[0].click(); await articles[0].click();
await sleep(500)
await download(driver); await download(driver);
console.log(`downloading ${from.isoDate()}...`); console.log(`downloading ${from.isoDate()}...`);
await sleep(500)
// do this in the background // do this in the background
moveDownload(tmpDir, outDir, from); moveDownload(tmpDir, outDir, from);

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "nzz-downloader", "name": "nzz-downloader",
"version": "0.1.2", "version": "0.1.3",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "nzz-downloader", "name": "nzz-downloader",
"version": "0.1.2", "version": "0.1.3",
"description": "", "description": "",
"main": "nzz.js", "main": "nzz.js",
"author": "Sebastian Hugentobler", "author": "Sebastian Hugentobler",