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
import { epicTvDiscounts } from "https://esm.town/v/marksteve/epicTvDiscounts";
import { getEpicTvProduct } from "https://esm.town/v/marksteve/getEpicTvProduct";
import { set } from "https://esm.town/v/std/set?v=11";
import { telegram } from "https://esm.town/v/stevekrouse/telegram?v=4";
export const checkEpicTvDiscounts = async (user: string, secret: string, watchList: {
url: string;
targetDiscount: number;
}[]) => {
for (let { url, targetDiscount } of watchList) {
const product = await getEpicTvProduct(url);
console.log({ product });
const discount = parseFloat(product.discount);
if (isNaN(discount)) {
console.log(`No discount for ${product.name}`);
continue;
}
if (epicTvDiscounts[url] === discount) {
console.log(`No discount change for ${product.name}`);
continue;
}
else {
epicTvDiscounts[url] = discount;
}
if (parseFloat(product.discount) < targetDiscount) {
console.log(`Target discount not met for ${product.name}`);
continue;
}
telegram(
secret,
`${product.name} is ${product.discount} off!\n${product.oldPrice} ➡️ ${product.price}`,
);
}
await set("epicTvDiscounts", epicTvDiscounts);
return epicTvDiscounts;
};
1
2
3
4
import { telegramText } from "https://esm.town/v/stevekrouse/telegram";
const statusResponse = await telegramText("Hello from Val.Town!!");
console.log(statusResponse);
1
2
3
4
5
6
import { telegramPhoto } from "https://esm.town/v/stevekrouse/telegram";
const statusResponse = await telegramPhoto({
photo: "https://placekitten.com/200/300",
});
console.log(statusResponse);
1
2
3
4
5
6
7
8
9
import process from "node:process";
import { telegram as telegram2 } from "https://esm.town/v/stevekrouse/telegram?v=4";
export let telegram = (message, options = undefined) =>
telegram2(
process.env.telegram_me,
message,
options,
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import process from "node:process";
import { telegram } from "https://esm.town/v/stevekrouse/telegram?v=4";
export const canetDeMarResidus = async () => {
const residus = [
"Organica i Envasos",
"Res",
"Organica",
"Rebuig",
"Organica i Envasos",
"Paper i Cartro",
"Organica",
];
const day = new Date().getDay();
const today = residus[day];
return telegram(
process.env.telegram,
`Avui toca: ${today}`,
);
};
1
Next