-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.js
54 lines (43 loc) · 1.49 KB
/
usage.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
50
51
52
53
54
require("dotenv").config();
const axios = require("axios").default;
if (!process.env.ACCOUNT_NUMBER || !process.env.ZIP_CODE)
throw new Error("Mediacom Account Number and Zip Code must be set");
const accountNumber = process.env.ACCOUNT_NUMBER;
const zipCode = process.env.ZIP_CODE;
async function start() {
const response = await axios.postForm(
"https://mediacom.openvault.us/csr/accountQuery.action",
{
accountNumber,
zipCode,
x: 26,
y: 16,
}
);
const webpage = response.data.toString();
const percentLine = webpage.match(/<span class="subTitleRed">\d*%/)[0];
const percent = percentLine.substring(26, percentLine.indexOf("%"));
const allowedLine = webpage.match(/max: \d+,/)[0];
const allowed = allowedLine.substring(5, allowedLine.indexOf(","));
const uploadLine = webpage.match(
/usageCurrentUpData\.push\([0-9]\d*(\.\d+)?\)/
)[0];
const upload = uploadLine.substring(24, uploadLine.indexOf(")"));
const downloadLine = webpage.match(
/usageCurrentDnData\.push\([0-9]\d*(\.\d+)?\)/
)[0];
const download = downloadLine.substring(24, downloadLine.indexOf(")"));
const totalLine = webpage.match(
/usageCurrentData\.push\([0-9]\d*(\.\d+)?\)/
)[0];
const total = totalLine.substring(22, totalLine.indexOf(")"));
const result = `{
percent: ${parseInt(percent)},
allowed: ${parseInt(allowed)},
upload: ${parseFloat(upload)},
download: ${parseFloat(download)},
total: ${parseFloat(total)},
}`;
console.log(result);
}
start();