From afc15370983aa9dc2786f5e1ec3f377ec2018e05 Mon Sep 17 00:00:00 2001
From: Cory Dransfeldt <coryd@hey.com>
Date: Thu, 4 Apr 2024 16:47:10 -0700
Subject: [PATCH] chore: debug

---
 plugins/fetch-charts/index.js          | 30 +++++++++++++++++++++++
 plugins/fetch-charts/manifest.yaml     |  1 +
 plugins/fetch-charts/package-lock.json | 34 ++++++++++++++++++++++++++
 plugins/fetch-charts/package.json      | 11 +++++++++
 4 files changed, 76 insertions(+)
 create mode 100644 plugins/fetch-charts/index.js
 create mode 100644 plugins/fetch-charts/manifest.yaml
 create mode 100644 plugins/fetch-charts/package-lock.json
 create mode 100644 plugins/fetch-charts/package.json

diff --git a/plugins/fetch-charts/index.js b/plugins/fetch-charts/index.js
new file mode 100644
index 00000000..68752b23
--- /dev/null
+++ b/plugins/fetch-charts/index.js
@@ -0,0 +1,30 @@
+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))
+}
\ No newline at end of file
diff --git a/plugins/fetch-charts/manifest.yaml b/plugins/fetch-charts/manifest.yaml
new file mode 100644
index 00000000..b26886f1
--- /dev/null
+++ b/plugins/fetch-charts/manifest.yaml
@@ -0,0 +1 @@
+name: netlify-plugin-fetch-scrobbles
\ No newline at end of file
diff --git a/plugins/fetch-charts/package-lock.json b/plugins/fetch-charts/package-lock.json
new file mode 100644
index 00000000..3f84b0d0
--- /dev/null
+++ b/plugins/fetch-charts/package-lock.json
@@ -0,0 +1,34 @@
+{
+  "name": "netlify-plugin-fetch-charts",
+  "version": "0.0.8",
+  "lockfileVersion": 3,
+  "requires": true,
+  "packages": {
+    "": {
+      "name": "netlify-plugin-fetch-charts",
+      "version": "0.0.8",
+      "devDependencies": {
+        "@netlify/blobs": "^7.3.0",
+        "luxon": "^3.4.4"
+      }
+    },
+    "node_modules/@netlify/blobs": {
+      "version": "7.3.0",
+      "resolved": "https://registry.npmjs.org/@netlify/blobs/-/blobs-7.3.0.tgz",
+      "integrity": "sha512-wN/kNTZo4xjlUM/C0WILOkJbe8p4AFquSGkZEIoIcgnsx5ikp2GyqGiq1WMLee7QdbnqeIV2g2hn/PjT324E5w==",
+      "dev": true,
+      "engines": {
+        "node": "^14.16.0 || >=16.0.0"
+      }
+    },
+    "node_modules/luxon": {
+      "version": "3.4.4",
+      "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz",
+      "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==",
+      "dev": true,
+      "engines": {
+        "node": ">=12"
+      }
+    }
+  }
+}
diff --git a/plugins/fetch-charts/package.json b/plugins/fetch-charts/package.json
new file mode 100644
index 00000000..df7ec883
--- /dev/null
+++ b/plugins/fetch-charts/package.json
@@ -0,0 +1,11 @@
+{
+  "name": "netlify-plugin-fetch-charts",
+  "version": "0.0.8",
+  "description": "netlify-plugin-fetch-charts",
+  "main": "index.js",
+  "type": "module",
+  "devDependencies": {
+    "@netlify/blobs": "^7.3.0",
+    "luxon": "^3.4.4"
+  }
+}