-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (39 loc) · 1.37 KB
/
index.js
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
require("dotenv").config({ path: __dirname + "/.env" });
const { twitterClient } = require("./twitterClient.js")
const axios = require('axios');
const tweet = async () => {
try {
const tweetText = `The URL **${storedSiteUrl}** has a safety status of **${storedSiteSafety}** on **Netsepio**`;
await twitterClient.v2.tweet(tweetText);
} catch (e) {
console.log(e)
}
}
let storedSiteSafety = "";
let storedSiteUrl = "";
const getLatestReview = async () => {
try {
console.log("stored", storedSiteSafety, storedSiteUrl)
const response = await axios.get(`https://gateway.netsepio.com/api/v1.0/getreviews?page=1&domain=`);
const review = response.data.payload.reviews[0];
const { siteSafety, siteUrl } = review;
if (siteSafety === storedSiteSafety && siteUrl === storedSiteUrl) {
console.log("No updates");
} else {
storedSiteSafety = siteSafety;
storedSiteUrl = siteUrl;
console.log("Updated values:");
console.log("Site Safety:", siteSafety);
console.log("Site URL:", siteUrl);
tweet()
}
} catch (error) {
console.error("Error fetching data:", error.message);
}
};
const runEvery30Seconds = () => {
setInterval(async () => {
await getLatestReview();
}, 30000);
};
runEvery30Seconds();