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 {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`);
|
||||||
|
|
||||||
|
if (needsOffset) {
|
||||||
|
date = date.addDays(1);
|
||||||
|
}
|
||||||
|
|
||||||
fs.watchFile(srcFile, () => {
|
if (!fs.existsSync(srcFile)) {
|
||||||
if (fs.existsSync(srcFile)) {
|
setTimeout(() => moveDownload(tmpDir, outDir, date), 5000);
|
||||||
fs.unwatchFile(srcFile);
|
}
|
||||||
if (needsOffset) {
|
|
||||||
date = date.addDays(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
2
package-lock.json
generated
@ -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": {
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user