Skip to content

Commit

Permalink
update breach-stats script
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Oct 10, 2018
1 parent 2e4319e commit e421f6d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scripts/quickest-breach-alerts.js → scripts/breach-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,27 @@ function dhm(t){
(async () => {
const breaches = await HIBP.req("/breaches");

let oldestBreachDate = new Date();
let oldestBreach = "";
let fastestResponseTime = Math.abs(new Date() - new Date(0));
let fastestResponseBreach = "";

for (const breach of breaches.body) {
console.log("checking response time for breach: ", breach.Name);
const responseTime = Math.abs(new Date(breach.BreachDate) - new Date(breach.AddedDate));
console.log("checking breach: ", breach.Name);
const breachDate = new Date(breach.BreachDate);
if (breachDate < oldestBreachDate){
oldestBreachDate = breachDate;
oldestBreach = breach.Name;
}
const responseTime = Math.abs(breachDate - new Date(breach.AddedDate));
if (responseTime < fastestResponseTime) {
fastestResponseTime = responseTime;
fastestResponseBreach = breach.Name;
}
}

console.log("fastest breach response time (dd:hh:mm): ", dhm(Math.abs(fastestResponseTime)));
console.log("on breach: ", fastestResponseBreach);
console.log("===========================");
console.log("oldest breach: ", oldestBreach, " on date: ", oldestBreachDate);
console.log("fastest breach response time (dd:hh:mm): ", dhm(Math.abs(fastestResponseTime)), " for breach: ", fastestResponseBreach);
})();

0 comments on commit e421f6d

Please sign in to comment.