chet/watchWebsite

Forks

Forked 1 time
Runs every 6 hrs
Fork
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
import { diffHtml } from "https://esm.town/v/chet/diffHtml";
import { blob } from "https://esm.town/v/std/blob?v=11";
import { email } from "https://esm.town/v/std/email?v=11";
import { fetch } from "https://esm.town/v/std/fetch";
export const watchWebsite = async () => {
const url = "https://www.margarethowell.co.uk/us/men/shop/shoes/raw-edge-derby-leather-black";
const newHtml = await fetch(url).then(r => r.text());
const key = "watch:" + url;
let oldHtml = "";
try {
oldHtml = await blob.get(key).then(r => r.text());
} catch (error) {
console.log("error");
}
await blob.set(key, newHtml);
if (!oldHtml) {
console.log("NO OLD", { oldHtml, newHtml });
return;
}
const diff = diffHtml(oldHtml, newHtml);
if (!diff) {
console.log("NO DIFF", { oldHtml, newHtml });
return;
}
console.log("DIFF", diff);
email({ subject: `Diff for ${url}`, text: diff });
};
1
Next