Runs every 1 hrs
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
import { blob } from "https://esm.town/v/std/blob?v=12";
import { email } from "https://esm.town/v/std/email";
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
export default async function(interval: Interval) {
const lastLakeTemp = await blob.getJSON("lastLakeTemp");
const temperature = await getLakeTemp();
console.log(temperature);
// Welcome email the first time you run the program and establish a baseline lake temp
if (!lastLakeTemp) {
await blob.setJSON("lastLakeTemp", temperature);
await email({
subject: `Welcome to Candlewood Lake Temperature Alerts! Current Temperature: ${temperature}°F`,
text:
`Howdy Surfer, \n\nWelcome to Candlewood Lake Temperature Alerts! \n\nThe current temperature of Candlewood Lake is ${temperature}°F. \n\nHappy Surfing!`,
});
console.log("sent email");
return;
}
const change = Math.abs(temperature - lastLakeTemp);
// Email for cold water conditions
if (change > 1 && temperature < 75) {
await blob.setJSON("lastLakeTemp", temperature);
await email({
subject: `Candlewood Lake Temperature Alert: ${temperature}°F`,
text:
`Sup Surfer! \n\nThe temperature of Candlewood Lake has changed from ${lastLakeTemp}°F to ${temperature}°F. \n\nBrace for frigid waves! `,
});
console.log("sent email");
}
// Email for warm water conditions
if (change > 1 && temperature >= 75) {
await blob.setJSON("lastLakeTemp", temperature);
await email({
subject: `Candlewood Lake Temperature Alert: ${temperature}°F`,
text:
`Sup Surfer! \n\nThe temperature of Candlewood Lake has changed from ${lastLakeTemp}°F to ${temperature}°F. \n\nWonderful warm waves are in your future! `,
});
console.log("sent email");
}
}
export async function getLakeTemp() {
const result = await fetchText("https://www.omniafishing.com/w/candlewood-lake-3-fishing-reports/current-conditions");
const temperature = result.match(/<strong>([0-9]+)/)[1];
return parseInt(temperature);
}