Daniel Miller

Daniel Miller

genius-lyrics-lookup

by Daniel Miller
// Menu: Genius Lyrics Search
let Genius = await npm('genius-lyrics-api')
let geniusUserToken = await env("GENIUS_AUTH_TOKEN")
import { getLyrics, searchSong } from 'genius-lyrics-api';
let songTitle = await arg("Song Title")
let options = {
apiKey: geniusUserToken,
title: songTitle,
artist: '',
optimizeQuery: true
}
let returnedSongs = await(searchSong(options).then((r) => r))
let returnedSongTitles = returnedSongs.map(s => s.title)
let chosenSongTitle = await arg("Which song?", returnedSongTitles)
let songData = returnedSongs.filter(s => s.title == chosenSongTitle)
let lyrics = await(getLyrics(songData[0].url).then((r) => r))
let whatToDo = await arg("", ["Copy", "View", "Visit"])
if (whatToDo == "Copy") copy(lyrics)
else if (whatToDo == "View") await textarea(lyrics)
else if (whatToDo == "Visit") await focusTab(songData[0].url)
let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let {data} = await post(
`https://api.notion.com/v1/databases/${databaseID}/query`,
{
"filter": {
"and": [
{
"property": "Status",
"select": {
"does_not_equal": "Done"
}
},
{
"property": "Status",
"select": {
"does_not_equal": "Archive"
}
}
]
},
page_size: 100
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
"Content-Type": "application/json",
"Notion-Version": "2021-05-13"
}
})
let tasks = data.results
let task = tasks[Math.floor(Math.random() * tasks.length)];
let pageID = task.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)
await focusTab(pageURL, "Google Chrome Beta")
let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let {data} = await post(
`https://api.notion.com/v1/databases/${databaseID}/query`,
{
"filter":
{
"property": "Status",
"select": {
"is_empty": true
}
},
page_size: 50
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
"Content-Type": "application/json",
"Notion-Version": "2021-05-13"
}
})
let tasks = data.results
let task = tasks[Math.floor(Math.random() * tasks.length)];
let pageID = task.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)
await focusTab(pageURL, "Google Chrome Beta")

post-to-notion

by Daniel Miller
<img width="418" alt="Screen Shot 2021-05-19 at 11 06 46 PM" src="https://user-images.githubusercontent.com/124208/118917657-f8c41e00-b8f6-11eb-9c5d-de7be826ec4c.png">
let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let content = await arg('Enter Task')
let {data} = await post(
'https://api.notion.com/v1/pages', {
"parent": { "database_id": databaseID },
"properties": {
"Name": {
"title": [
{
"text": {
"content": content
}
}
]
}
}
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
}
})
let pageID = data.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)
let notionToken = await env('NOTION_USER_TOKEN')
let databaseID = "3859b567fda3464ea5a69d5ccb56274b"
let content = await arg('Enter Task')
let {data} = await post(
'https://api.notion.com/v1/pages', {
"parent": { "database_id": databaseID },
"properties": {
"Name": {
"title": [
{
"text": {
"content": content
}
}
]
}
}
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
"Content-Type": "application/json",
"Notion-Version": "2021-05-13"
}
})
let bodyContent = await arg('Enter Content')
let {bodyData} = await patch(
`https://api.notion.com/v1/blocks/${data.id}/children`, {
"children": [
{
"object": "block",
"type": "paragraph",
"paragraph": {
"text": [
{
"type": "text",
"text": {
"content": bodyContent
}
}
]
}
}
]
},
{
headers: {
Authorization: `Bearer ${notionToken}`,
"Content-Type": "application/json",
"Notion-Version": "2021-05-13"
}
})
let pageID = data.id.replace(/-/g, "");
let pageURL = `https://notion.so/${databaseID}?p=${pageID}`
copy(pageURL)

let {format} = await npm('date-fns')
let title = await arg('Name of post')
let file_title = title.toLowerCase().replaceAll(' ', '-')
let posts_path = '/Users/danielmiller/code/daniel-industries/_posts/'
let date = new Date()
let date_for_path = format(date, 'yyyy-MM-dd')
let date_for_yml = format(date, 'yyyy-MM-dd hh:mm:ss z')
let file_path = posts_path + date_for_path + '-' + file_title + '.markdown'
let file_contents = `---
layout: post
title: "${ title }"
excerpt:
date: ${ date_for_yml }
categories:
---
`
writeFile(file_path, file_contents)
exec(`code ${file_path} --new-window`)