Readme

Candlewood Lake Temp Alerts

This val monitors the water temperature of Candlewood Lake and sends an email alert when it changes. The val works by checking the current temperature of Candlewood Lake against the last recorded temperature and triggers an email notification if the change meets or exceeds 2°F. The email includes the new temperature and has a variable message based on hot (>= 75°F) or cold (<75°F) conditions.

Fork this val to get these notifications on your inbox.

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);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
v123 was merged from the PR "little edits" by stevekrouse
Comments
Nobody has commented on this val yet: be the first!
May 21, 2024