Created
November 27, 2016 23:19
-
-
Save Markavian/289ddcf64934d053a801484e82d42d79 to your computer and use it in GitHub Desktop.
r/a/dio favourites played in the past 24 hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var favesData = require('./mkv25_faves.json'); | |
var faves = favesData.map((item) => { | |
var copy = Object.assign({}, item); | |
copy.lastplayeddate = new Date(item.lastplayed); | |
copy.lastplayedts = Math.round(copy.lastplayeddate.getTime() / 1000); | |
return copy; | |
}); | |
var ts = Math.round(new Date().getTime() / 1000); | |
var tsYesterday = ts - (24 * 3600); | |
var playedInPast24Hours = faves.filter((item) => { | |
return item.lastplayedts >= tsYesterday; | |
}); | |
var NL = '\n'; | |
console.log('Favourites played in the past 24 hours:', NL); | |
playedInPast24Hours.sort((a,b) => { | |
return a.lastplayedts < b.lastplayedts; | |
}).forEach((item) => { | |
console.log(timeSince(item.lastplayeddate) + ' ago'); | |
console.log('', item.meta, NL); | |
}); | |
function timeSince(date) { | |
if (typeof date !== 'object') { | |
date = new Date(date); | |
} | |
var seconds = Math.floor((new Date() - date) / 1000); | |
var intervalType; | |
var interval = Math.floor(seconds / 31536000); | |
if (interval >= 1) { | |
intervalType = 'year'; | |
} else { | |
interval = Math.floor(seconds / 2592000); | |
if (interval >= 1) { | |
intervalType = 'month'; | |
} else { | |
interval = Math.floor(seconds / 86400); | |
if (interval >= 1) { | |
intervalType = 'day'; | |
} else { | |
interval = Math.floor(seconds / 3600); | |
if (interval >= 1) { | |
intervalType = "hour"; | |
} else { | |
interval = Math.floor(seconds / 60); | |
if (interval >= 1) { | |
intervalType = "minute"; | |
} else { | |
interval = seconds; | |
intervalType = "second"; | |
} | |
} | |
} | |
} | |
} | |
if (interval > 1 || interval === 0) { | |
intervalType += 's'; | |
} | |
return interval + ' ' + intervalType; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Favourites played in the past 24 hours: | |
5 hours ago | |
Tutti Sound - Voyage 1969 & 1970 | |
11 hours ago | |
IOSYS - Cirno's Perfect Math Class | |
12 hours ago | |
kagomeP - Karyoku | |
16 hours ago | |
Madeon x Monogatari - Slice The Snake | |
17 hours ago | |
ntb - YAYOI is Mind Killer -High edit- | |
18 hours ago | |
Ni-Sokkususu - KN33S0XXX | |
19 hours ago | |
Nakajima Megumi - TRY UNITE! | |
20 hours ago | |
Shibayan feat. Yanagi Nagi - Fall In The Dark |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment