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
import { blob } from "https://esm.town/v/std/blob";
import { email } from "https://esm.town/v/std/email";
const ipqsApiKey = Deno.env.get("IPQS_API_KEY");
const ipAddress = "8.8.8.8";
const ipDataName = "googleIpqsData";
async function sendEmail(oldData, newData) {
const emailBody = `The IPQS score for the IP address "${ipAddress}" has changed.
Old evaluation:
${JSON.stringify(oldData, null, 2)}
New evaluation:
${JSON.stringify(newData, null, 2)}`;
await email({ subject: `IPQS score changed: ${ipAddress}`, text: emailBody });
}
export async function checkIp() {
const result = await fetch(`https://ipqualityscore.com/api/json/ip/${ipqsApiKey}/${ipAddress}`);
const newData = await result.json();
const oldData = await blob.getJSON(ipDataName);
await blob.setJSON(ipDataName, newData);
if (!oldData) {
return;
}
if (oldData.fraud_score !== newData.fraud_score) {
await sendEmail(oldData, newData);
}
}
await checkIp();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 25, 2024