Skip to content

Commit

Permalink
Capturas con nombre
Browse files Browse the repository at this point in the history
  • Loading branch information
jzavala-gonzalez committed May 31, 2024
1 parent cfa934c commit 8b5f1c3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
capturas/*

# Logs
logs
*.log
Expand Down
24 changes: 22 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// Basado en este tutorial:
// https://www.bannerbear.com/blog/how-to-take-screenshots-with-puppeteer/

const puppeteer = require('puppeteer');
import puppeteer from 'puppeteer';

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
import timezone from 'dayjs/plugin/timezone.js';

dayjs.extend(utc);
dayjs.extend(timezone);

const tz = 'America/Puerto_Rico';
dayjs.tz.setDefault(tz);

const filename_datetime_format = 'YYYY-MM-DDTHH-mm-ssZZ';

(async () => {

Expand All @@ -18,6 +30,12 @@ await page.setViewport({
deviceScaleFactor: 2,
});

// Guardar fecha de ahora
const now = dayjs();
const filename_datetime = now.format(filename_datetime_format);
console.log('now (ISO):', now.toISOString(), '(debe ser UTC)');
console.log('filename_datetime:', filename_datetime, '(debe ser Puerto Rico)');

// Abrir una URL
const website_url = 'https://miluma.lumapr.com/outages/serviceStatus';
await page.goto(website_url, { waitUntil: 'networkidle0' });
Expand All @@ -28,7 +46,9 @@ await page.waitForSelector('div.jss55', { visible: true });
await new Promise(resolve => setTimeout(resolve, 500))

// Tomar una captura de pantalla
await page.screenshot({ path: 'screenshot.png' });
const screenshot_filename = `luma_estatus_captura__${filename_datetime}.png`;
console.log('Guardando como:', screenshot_filename);
await page.screenshot({ path: 'capturas/'+screenshot_filename });

// Cerrar el navegador
await browser.close();
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "",
"license": "MIT",
"dependencies": {
"dayjs": "^1.11.11",
"puppeteer": "^22.10.0"
}
}

0 comments on commit 8b5f1c3

Please sign in to comment.