This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
coryd.dev-eleventy/plugins/fetch-charts/index.js
Cory Dransfeldt afc1537098
chore: debug
2024-04-04 16:47:10 -07:00

30 lines
No EOL
1.1 KiB
JavaScript

import { getStore, setEnvironmentContext } from '@netlify/blobs'
import { DateTime } from 'luxon'
import fs from 'fs'
const getKeys = () => {
const currentDate = DateTime.now()
return [
`${currentDate.year}-${currentDate.weekNumber}`
`${currentDate.minus({ weeks: 1 }).year}-${currentDate.minus({ weeks: 1 }).weekNumber}`,
`${currentDate.minus({ weeks: 2 }).year}-${currentDate.minus({ weeks: 2 }).weekNumber}`,
`${currentDate.minus({ weeks: 3 }).year}-${currentDate.minus({ weeks: 3 }).weekNumber}`,
`${currentDate.minus({ weeks: 4 }).year}-${currentDate.minus({ weeks: 4 }).weekNumber}`,
]
}
export const onPreBuild = async ({ constants }) => {
const keys = getKeys()
const data = []
setEnvironmentContext({
siteID: constants.SITE_ID,
token: constants.NETLIFY_API_TOKEN,
})
const scrobbles = getStore('scrobbles')
keys.forEach(async key => {
const scrobbleData = await scrobbles.get(key, { type: 'json'})
data.push(scrobbleData['data'])
})
console.log(data)
fs.writeFileSync('./src/_data/json/scrobbles-month-chart.json', JSON.stringify(data))
}