mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-22 18:35:40 +00:00
Added spotify minutes listened metric to dashboard
This commit is contained in:
parent
4dd5e30f81
commit
520f45cab8
@ -6,3 +6,4 @@ DATABASE_URL=
|
|||||||
SHADOW_DATABASE_URL=
|
SHADOW_DATABASE_URL=
|
||||||
GITHUB_ACCESS_TOKEN=
|
GITHUB_ACCESS_TOKEN=
|
||||||
GITHUB_USERNAME=
|
GITHUB_USERNAME=
|
||||||
|
STATSFM_USERNAME=
|
@ -2,6 +2,7 @@ import {getTotalFollowers, getTotalRepos, getTotalStars} from '@/lib/github'
|
|||||||
import {getAllArticles} from '@/lib/getAllArticles'
|
import {getAllArticles} from '@/lib/getAllArticles'
|
||||||
import {getTopArtist, getTopGenre} from '@/lib/spotify'
|
import {getTopArtist, getTopGenre} from '@/lib/spotify'
|
||||||
import {getViews} from '@/lib/views'
|
import {getViews} from '@/lib/views'
|
||||||
|
import {getStats} from '@/lib/statsfm'
|
||||||
import {Metric} from '@/types'
|
import {Metric} from '@/types'
|
||||||
|
|
||||||
export async function getDashboardData() {
|
export async function getDashboardData() {
|
||||||
@ -14,12 +15,19 @@ export async function getDashboardData() {
|
|||||||
const totalArticles = (await getAllArticles()).length
|
const totalArticles = (await getAllArticles()).length
|
||||||
const totalArticleViews = (await getViews()).views
|
const totalArticleViews = (await getViews()).views
|
||||||
const topArtist = await getTopArtist()
|
const topArtist = await getTopArtist()
|
||||||
const topGenre = await getTopGenre()
|
const {genre} = await getTopGenre()
|
||||||
|
const {minutesListened} = await getStats()
|
||||||
|
|
||||||
const metrics: Metric[] = [
|
const metrics: Metric[] = [
|
||||||
|
{
|
||||||
|
title: "Minutes listened",
|
||||||
|
value: minutesListened,
|
||||||
|
group: "Spotify",
|
||||||
|
href: "https://open.spotify.com/?"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Top genre",
|
title: "Top genre",
|
||||||
value: topGenre.genre,
|
value: genre,
|
||||||
group: "Spotify",
|
group: "Spotify",
|
||||||
href: "https://open.spotify.com/?"
|
href: "https://open.spotify.com/?"
|
||||||
},
|
},
|
||||||
|
25
lib/statsfm.ts
Normal file
25
lib/statsfm.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import fetch from 'node-fetch'
|
||||||
|
|
||||||
|
const STATSFM_USERNAME = process.env.STATSFM_USERNAME
|
||||||
|
const STATSFM_LIFETIME_STATS = `https://beta-api.stats.fm/api/v1/users/${STATSFM_USERNAME}/streams/stats?range=lifetime`
|
||||||
|
|
||||||
|
type StatsFmResponse = {
|
||||||
|
items: {
|
||||||
|
durationMs: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getStats = async () => {
|
||||||
|
const response = await fetch(STATSFM_LIFETIME_STATS, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
}).then(r => r.json()) as StatsFmResponse
|
||||||
|
|
||||||
|
const minutesListened = ((response.items.durationMs / 1000) / 60).toFixed(0)
|
||||||
|
|
||||||
|
return {
|
||||||
|
minutesListened
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user