-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathog.ts
52 lines (49 loc) · 1.15 KB
/
og.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as playwright from "playwright";
import { getHtml } from "./util/template";
import {
getTotalConfirmed,
getTotalRecovered,
getTotalDeaths,
getLastUpdate,
getDailyCases,
} from "./util/api";
import { writeTempFile, pathToFileURL } from "./util/file";
export async function og() {
try{
const [
confirmed,
recovered,
deaths,
lastUpdate,
dailyCases,
] = await Promise.all([
getTotalConfirmed(),
getTotalRecovered(),
getTotalDeaths(),
getLastUpdate(),
getDailyCases(),
]);
const html = getHtml({
confirmed,
recovered,
deaths,
lastUpdate,
dailyCases,
width: 1200,
height: 600,
});
const text = "textwoot";
const filePath = await writeTempFile(text, html);
const fileUrl = pathToFileURL(filePath);
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(fileUrl);
await page.screenshot({ path: `og.png` });
await browser.close();
return true
}catch(e){
console.log(e.message)
return false
}
}