Added spotify metric to dashboard

This commit is contained in:
r-freeman 2023-02-18 22:51:56 +00:00
parent 576c071a46
commit f38f432bad
2 changed files with 11 additions and 2 deletions

View File

@ -16,7 +16,7 @@ export async function getDashboardData() {
const totalArticleViews = (await getViews()).views
const topArtist = await getTopArtist()
const {genre} = await getTopGenre()
const {minutesListened, streams} = await getStats()
const {hoursListened, minutesListened, streams} = await getStats()
const metrics: Metric[] = [
{
@ -25,6 +25,12 @@ export async function getDashboardData() {
group: "Spotify",
href: "https://open.spotify.com/?"
},
{
title: "Hours listened",
value: +hoursListened,
group: "Spotify",
href: "https://open.spotify.com/?"
},
{
title: "Minutes listened",
value: +minutesListened,

View File

@ -18,10 +18,13 @@ export const getStats = async () => {
}
}).then(r => r.json()) as StatsFmResponse
const minutesListened = ((response.items.durationMs / 1000) / 60).toFixed(0)
const {durationMs} = response.items
const hoursListened = (durationMs / 3_600_000).toFixed(0)
const minutesListened = (durationMs / 60_000).toFixed(0)
const streams = response.items.count
return {
hoursListened,
minutesListened,
streams
}