marksteve/telegram

References

Referenced 1 time
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
Next