-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
87 lines (77 loc) · 2.39 KB
/
index.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Parser from "rss-parser";
import notifier from "node-notifier";
import os from "os";
import Nodemailer from "nodemailer";
import dotenv from "dotenv";
dotenv.config();
const createTransporter = () => {
if (!process.env.EMAIL_HOST) return;
return Nodemailer.createTransport({
host: process.env.EMAIL_HOST,
auth: { user: process.env.EMAIL_USER, pass: process.env.EMAIL_PASS },
});
};
const transporter = createTransporter();
const osType = os.type() as "Linux" | "Darwin" | "Windows_NT";
const parser = new Parser();
let cachedFeed3060_3070: Parser.Item[] | undefined;
let cachedFeed3080_3090: Parser.Item[] | undefined;
const checkSweclockers = async (
url: string,
cachedFeed: Parser.Item[] | undefined
) => {
const feed = await parser.parseURL(url);
if (!cachedFeed) {
cachedFeed = feed.items;
}
const latestFeedItem = feed.items[0];
const cachedLastestFeedItem = cachedFeed[0];
if (!latestFeedItem || !latestFeedItem.isoDate) return;
if (!cachedLastestFeedItem || !cachedLastestFeedItem.isoDate) return;
const latestDate = Date.parse(latestFeedItem.isoDate);
const cachedLatestDate = Date.parse(cachedLastestFeedItem.isoDate);
if (latestDate > cachedLatestDate) {
console.log(
"Quick there is a graphics card on the loose!",
`${latestFeedItem.title} ${latestFeedItem.contentSnippet}`
);
if (osType === "Linux") {
notifier.notify(
`${latestFeedItem.title} ${latestFeedItem.contentSnippet}`
);
} else {
notifier.notify({
title: latestFeedItem.title,
open: latestFeedItem.link,
});
}
if (transporter) {
await transporter.sendMail({
to: [process.env.EMAIL1 as string, process.env.EMAIL2 as string],
subject: latestFeedItem.title,
html: latestFeedItem.content,
from: "[email protected]",
});
}
}
cachedFeed = feed.items;
};
checkSweclockers(
"https://www.sweclockers.com/feeds/forum/trad/1625960",
cachedFeed3060_3070
);
checkSweclockers(
"https://www.sweclockers.com/feeds/forum/trad/1625959",
cachedFeed3080_3090
);
setInterval(() => {
console.log("Checking sweclockers", new Date().toLocaleString());
checkSweclockers(
"https://www.sweclockers.com/feeds/forum/trad/1625960",
cachedFeed3060_3070
);
checkSweclockers(
"https://www.sweclockers.com/feeds/forum/trad/1625959",
cachedFeed3080_3090
);
}, 1000 * 60);