Readme

Website Downtime Alert

This val checks the availability of a specified website. If it's down or not returning a 200 OK status, it triggers an email alert. The email includes the date, time (in UTC), and the reason for the downtime, providing a way to monitor website availability.

Fork this val and edit the URL variable to set up downtime notifications for your website.

Runs every 30 days
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
52
53
54
55
56
57
58
import { email } from "https://esm.town/v/std/email";
import { md5 } from "https://esm.town/v/tr3ntg/md5?v=1";
// import { sqlite } from "https://esm.town/v/std/sqlite";
// await sqlite.execute(`CREATE TABLE IF NOT EXISTS kv(
// key text unique,
// value text
// )`);
// const KEY = "VOETBAL_SHIRT_HASH";
export async function download() {
// Replace this URL with the website you want to track
const URL = "https://www.knvbshop.nl/nike-nederlands-elftal-thuisshirt-2024-2026.html#size=XL";
const unless = [
">XL <span class=\"sep\">-</span> <span class=\"label\">Niet op voorraad",
">XL <span class=\"sep\">-</span> <span class=\"label\">Verwacht op",
];
const now = new Date();
let ok = false;
let res;
let reason: string;
try {
res = await fetch(URL, { redirect: "follow" });
if (!res.ok) {
throw await res.text();
}
ok = true;
} catch (e) {
reason = `couldn't fetch: ${e}`;
await email({ subject: "could not update the contents of the change", text: reason });
}
if (ok) {
const html = await res.text();
// const hash = md5(html);
// const lastHash = (await sqlite.execute({
// sql: `select key, value from kv where key = :key`,
// args: { key: KEY },
// })).rows[0]?.[1];
if (html.includes("select bd_clothing_size") && !unless.some(text => html.includes(text))) {
// await sqlite.execute({
// sql: `replace into kv(key, value) values (:key, :value)`,
// args: { key: KEY, value: hash },
// });
const subject = `Voetbal shirt available in XL!`;
await email({ subject, text: `Last check: ${now}\nLink: ${URL}\n` });
}
} else {
console.log("Maat selector not found");
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 15, 2024