Skip to content

Instantly share code, notes, and snippets.

@nirewen
Created April 20, 2022 14:46
Show Gist options
  • Save nirewen/7c38548c4a2b243f4a60ac76e519c251 to your computer and use it in GitHub Desktop.
Save nirewen/7c38548c4a2b243f4a60ac76e519c251 to your computer and use it in GitHub Desktop.
Generate a Notion database with all days of the year

This is a simple Node.JS script to generate a .CSV file to merge with a previously created Notion database.

It's supposed to be used with a Habit Tracker of sorts. It generates all days of the specified year, naming each page "Day #".

It also includes the week day (sunday, monday, ...)

It's easier to generate this from a script, and then use Notion to add the rest, like all the habits and database relationships there.

Packages

It only requires 1 package, @js-temporal/polyfill, an implementation of the Temporal API for Node.JS.

Since it's an .mjs file, the Node repository has to be of type module (set "type": "module" in package.json)

import fs from 'node:fs'
import { Temporal } from '@js-temporal/polyfill'
let date = Temporal.PlainDate.from({ year: 2022, month: 1, day: 1 })
const dates = []
const header = 'Name,Date,Weekday\n'
for (let i = 0; i < 365; i++) {
dates.push(
`"Day ${date.dayOfYear}",` + // page name
`"${date.toString().replace(/-/g, '/')}",` + // Date
`"${date.toLocaleString('en-US', { weekday: 'long' })}"` // Weekday
)
date = date.add({ days: 1 })
}
fs.writeFileSync('habits.csv', `${header}${dates.join('\n')}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment