This repository was archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (37 loc) · 1.22 KB
/
index.js
File metadata and controls
47 lines (37 loc) · 1.22 KB
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
#!/usr/bin/env node
const request = require("request");
const cliTable = require("cli-table");
const moment = require("moment");
if(process.argv.length === 2){
console.log("Correct usage: alipaczka [tracking number]");
process.exit();
}
const trackingNumber = process.argv[2];
request("https://alipaczka.pl/mobileAPI2.php?number=" + trackingNumber, function (error, response, body) {
if(error){
console.log("Something went wrong: " + error);
process.exit();
}
const json = JSON.parse(body);
if(json.error){
console.log("Error from Alipaczka service: " + json.error);
process.exit();
}
console.log("Tracking number: " + trackingNumber);
console.log("Delivered: " + json.isDelivered);
console.log("");
console.log("Package status:");
var table = new cliTable({
head: ["Date", "Status"],
colWidths: [30, (process.stdout.columns-33)]
});
for(x = 0; x < json.DataEntry.reverse().length; x++){
table.push(
[
moment(new Date(json.DataEntry[x]["time"] * 1000)).format("MMMM Do YYYY, H:mm:ss"),
json.DataEntry[x]["status"]
]
);
}
console.log(table.toString());
});