Skip to content

Commit

Permalink
fix ts headers
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Oct 7, 2024
1 parent 8c012d8 commit 771415f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 35 deletions.
21 changes: 7 additions & 14 deletions src/browserbase-experiment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env node
/* eslint-disable no-process-env */
import 'dotenv/config'

import fs from 'node:fs/promises'

import { input } from '@inquirer/prompts'
import { chromium } from 'playwright-core'

import { assert } from './utils'
import { assert, getEnv } from './utils'

// TODO: kindle pages don't seem to render properly in headless playwright,
// possibly due to webgl usage in the text renderer?
Expand All @@ -16,11 +14,11 @@ async function createSession() {
const res = await fetch('https://www.browserbase.com/v1/sessions', {
method: 'POST',
headers: {
'x-bb-api-key': `${process.env.BROWSERBASE_API_KEY}`,
'x-bb-api-key': `${getEnv('BROWSERBASE_API_KEY')}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
projectId: process.env.BROWSERBASE_PROJECT_ID,
projectId: getEnv('BROWSERBASE_PROJECT_ID'),
proxies: true
// TODO: browserbase fingerprint docs seem to be broken
// fingerprint: {
Expand All @@ -35,15 +33,15 @@ async function createSession() {
}

async function main() {
const amazonEmail = process.env.AMAZON_EMAIL
const amazonPassword = process.env.AMAZON_PASSWORD
const amazonEmail = getEnv('AMAZON_EMAIL')
const amazonPassword = getEnv('AMAZON_PASSWORD')
assert(amazonEmail, 'AMAZON_EMAIL is required')
assert(amazonPassword, 'AMAZON_PASSWORD is required')

const session = await createSession()
console.log(session)
const browser = await chromium.connectOverCDP(
`wss://connect.browserbase.com?apiKey=${process.env.BROWSERBASE_API_KEY}&sessionId=${session.id}`
`wss://connect.browserbase.com?apiKey=${getEnv('BROWSERBASE_API_KEY')}&sessionId=${session.id}`
)

// Getting the default context to ensure the sessions are recorded.
Expand Down Expand Up @@ -98,9 +96,4 @@ async function main() {
await browser.close()
}

try {
await main()
} catch (err) {
console.error('error', err)
process.exit(1)
}
await main()
16 changes: 5 additions & 11 deletions src/extract-kindle-book.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node
/* eslint-disable no-process-env */
import 'dotenv/config'

import fs from 'node:fs/promises'
Expand All @@ -12,6 +10,7 @@ import { chromium, type Locator } from 'playwright'
import {
assert,
deromanize,
getEnv,
normalizeAuthors,
parseJsonpResponse
} from './utils'
Expand All @@ -35,9 +34,9 @@ interface PageChunk {
}

async function main() {
const asin = process.env.ASIN
const amazonEmail = process.env.AMAZON_EMAIL
const amazonPassword = process.env.AMAZON_PASSWORD
const asin = getEnv('ASIN')
const amazonEmail = getEnv('AMAZON_EMAIL')
const amazonPassword = getEnv('AMAZON_PASSWORD')
assert(asin, 'ASIN is required')
assert(amazonEmail, 'AMAZON_EMAIL is required')
assert(amazonPassword, 'AMAZON_PASSWORD is required')
Expand Down Expand Up @@ -489,9 +488,4 @@ function parseTocItems(tocItems: TocItem[]) {
// }
// )

try {
await main()
} catch (err) {
console.error('error', err)
process.exit(1)
}
await main()
13 changes: 3 additions & 10 deletions src/transcribe-book-content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node
/* eslint-disable no-process-env */
import 'dotenv/config'

import fs from 'node:fs/promises'
Expand All @@ -9,7 +7,7 @@ import { globby } from 'globby'
import { OpenAIClient } from 'openai-fetch'
import pMap from 'p-map'

import { assert } from './utils'
import { assert, getEnv } from './utils'

type ContentChunk = {
index: number
Expand All @@ -19,7 +17,7 @@ type ContentChunk = {
}

async function main() {
const asin = process.env.ASIN
const asin = getEnv('ASIN')
assert(asin, 'ASIN is required')

const outDir = path.join('out', asin)
Expand Down Expand Up @@ -121,9 +119,4 @@ Do not include any additional text, descriptions, or punctuation. Ignore any emb
console.log(JSON.stringify(results, null, 2))
}

try {
await main()
} catch (err) {
console.error('error', err)
process.exit(1)
}
await main()

0 comments on commit 771415f

Please sign in to comment.