sanitizeFilename -> filenamify, use for datetime
This commit is contained in:
parent
c519ce0ce5
commit
2791112fd6
3 changed files with 8 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { chromium } from 'playwright'; // stealth plugin needs no outdated playwright-extra
|
||||
import path from 'path';
|
||||
import { dirs, jsonDb, datetime, stealth } from './util.js';
|
||||
import { dirs, jsonDb, datetime, stealth, filenamify } from './util.js';
|
||||
|
||||
const debug = process.env.PWDEBUG == '1'; // runs non-headless and opens https://playwright.dev/docs/inspector
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ try {
|
|||
console.log('Claimed successfully!');
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
const p = path.resolve(dirs.screenshots, 'epic-games', `${datetime().replaceAll(':', '.')}.png`);
|
||||
const p = path.resolve(dirs.screenshots, 'epic-games', `${filenamify(datetime())}.png`);
|
||||
await page.screenshot({ path: p, fullPage: true });
|
||||
console.info('Saved a screenshot of hcaptcha challenge to', p);
|
||||
console.error('Got hcaptcha challenge. To avoid it, get a link from https://www.hcaptcha.com/accessibility'); // TODO save this link in config and visit it daily to set accessibility cookie to avoid captcha challenge?
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { chromium } from 'playwright'; // stealth plugin needs no outdated playwright-extra
|
||||
import path from 'path';
|
||||
import { dirs, jsonDb, datetime, sanitizeFilename, stealth } from './util.js';
|
||||
import { dirs, jsonDb, datetime, stealth, filenamify } from './util.js';
|
||||
|
||||
const debug = process.env.PWDEBUG == '1'; // runs headful and opens https://playwright.dev/docs/inspector
|
||||
const show = process.argv.includes('show', 2);
|
||||
|
|
@ -77,7 +77,7 @@ try {
|
|||
console.log('Current free game:', title);
|
||||
// const img = await (await card.$('img.tw-image')).getAttribute('src');
|
||||
// console.log('Image:', img);
|
||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'internal', `${sanitizeFilename(title)}.png`);
|
||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'internal', `${filenamify(title)}.png`);
|
||||
await card.screenshot({ path: p });
|
||||
await (await card.$('button:has-text("Claim game")')).click();
|
||||
db.data.claimed.push({ title, time: datetime(), store: 'internal' });
|
||||
|
|
@ -123,7 +123,7 @@ try {
|
|||
}
|
||||
db.data.claimed.push({ title, time: datetime(), store, code, url: page.url() });
|
||||
// save screenshot of potential code just in case
|
||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'external', `${sanitizeFilename(title)}.png`);
|
||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'external', `${filenamify(title)}.png`);
|
||||
await page.screenshot({ path: p, fullPage: true });
|
||||
console.info('Saved a screenshot of page to', p);
|
||||
run.c_external++;
|
||||
|
|
@ -132,7 +132,7 @@ try {
|
|||
await page.goto(URL_CLAIM, {waitUntil: 'domcontentloaded'});
|
||||
await page.click('button[data-type="Game"]');
|
||||
} while (n);
|
||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', `${datetime().replaceAll(':', '.')}.png`);
|
||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', `${filenamify(datetime())}.png`);
|
||||
// await page.screenshot({ path: p, fullPage: true });
|
||||
await page.locator(games_sel).screenshot({ path: p });
|
||||
} catch(error) {
|
||||
|
|
|
|||
4
util.js
4
util.js
|
|
@ -19,8 +19,8 @@ export const jsonDb = async file => {
|
|||
return db;
|
||||
}
|
||||
|
||||
export const datetime = (d = new Date()) => d.toISOString();
|
||||
export const sanitizeFilename = s => s.replace(/[^a-z0-9_\-]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify
|
||||
export const datetime = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', '');
|
||||
export const filenamify = s => s.replaceAll(':', '.').replace(/[^a-z0-9 _\-.]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify - On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved.
|
||||
|
||||
// stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212
|
||||
const newStealthContext = async (browser, contextOptions = {}, debug = false) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue