-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
node_modules | ||
data*.json | ||
amazon_links.json | ||
records*.json | ||
records*.json | ||
books-notion-table.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// read supabase data and convert to csv from books table | ||
// convert to csv from books table w format: { title, book_id, author, cover_image_url } | ||
// NOTE TO SELF: this is a one-time script, so it's okay to use fs.appendFileSync here | ||
// open in Sheets and then share export as unicode csv and delete all rows in Notion with ctrl+a, delete after scrolling to the bottom | ||
|
||
|
||
import { createClient } from "@supabase/supabase-js"; | ||
import dotenv from "dotenv"; | ||
import fs from "fs"; | ||
|
||
dotenv.config(); | ||
|
||
const supabaseUrl = process.env.SUPABASE_URL; | ||
const supabaseKey = process.env.SUPABASE_KEY; | ||
const supabase = createClient(supabaseUrl, supabaseKey, { | ||
auth: { | ||
persistSession: false, | ||
}, | ||
}); | ||
|
||
const convertSupabaseBooksToCSV = async () => { | ||
const { data: books, error } = await supabase.from("books").select("*").limit(1000); | ||
|
||
if (error) throw error; | ||
|
||
const csv = books.map((book) => { | ||
return { | ||
title: book.title.replace(/,/g, ""), | ||
book_id: book.book_id, | ||
author: book.author.replace(/,/g, ""), | ||
cover_image_url: book.cover_image_url, | ||
wander_command: `/wander book_ids:${book.book_id}`, | ||
}; | ||
}); | ||
|
||
// add csv header and write to file | ||
const header = "title,book_id,author,cover_image_url,wander_command\n"; | ||
fs.writeFileSync("books-notion-table.csv", header); | ||
csv.forEach((row) => { | ||
fs.appendFileSync("books-notion-table.csv", `${row.title},${row.book_id},${row.author},${row.cover_image_url},${row.wander_command}\n`); | ||
}); | ||
|
||
|
||
}; | ||
|
||
convertSupabaseBooksToCSV(); |