more sleeps...
This commit is contained in:
parent
d3f6aeb62f
commit
5104bf7e2d
25
nzz.js
25
nzz.js
@ -48,7 +48,7 @@ function sleep(ms) {
|
||||
* @param {fs.PathLike} outDir Final destination directory.
|
||||
* @param {Date} date Date of the issue.
|
||||
*/
|
||||
async function moveDownload(tmpDir, outDir, date) {
|
||||
function moveDownload(tmpDir, outDir, date) {
|
||||
return new Promise(resolve => {
|
||||
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`);
|
||||
|
||||
if (needsOffset) {
|
||||
date = date.addDays(1);
|
||||
}
|
||||
|
||||
fs.watchFile(srcFile, () => {
|
||||
if (fs.existsSync(srcFile)) {
|
||||
fs.unwatchFile(srcFile);
|
||||
if (needsOffset) {
|
||||
date = date.addDays(1);
|
||||
}
|
||||
if (!fs.existsSync(srcFile)) {
|
||||
setTimeout(() => moveDownload(tmpDir, outDir, date), 5000);
|
||||
}
|
||||
|
||||
let destFile = path.join(outDir, `${date.isoDate()}.pdf`);
|
||||
fs.copyFileSync(srcFile, destFile);
|
||||
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
let destFile = path.join(outDir, `${date.isoDate()}.pdf`);
|
||||
fs.copyFileSync(srcFile, destFile);
|
||||
});
|
||||
}
|
||||
|
||||
@ -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);
|
||||
await endDate.clear();
|
||||
await endDate.sendKeys(dateString + Key.ENTER);
|
||||
await sleep(500);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,9 +153,11 @@ async function findIssues(driver, from, to, tmpDir, outDir) {
|
||||
try {
|
||||
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 sleep(500)
|
||||
|
||||
await download(driver);
|
||||
console.log(`downloading ${from.isoDate()}...`);
|
||||
await sleep(500)
|
||||
|
||||
// do this in the background
|
||||
moveDownload(tmpDir, outDir, from);
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nzz-downloader",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nzz-downloader",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "",
|
||||
"main": "nzz.js",
|
||||
"author": "Sebastian Hugentobler",
|
||||
|
Loading…
Reference in New Issue
Block a user