Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/utils/tweet_extraction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as cheerio from 'cheerio'
import fetch from 'node-fetch'

export async function extractTweetText(tweetUrl: string): Promise<string> {
const response = await fetch(tweetUrl, {
headers: {
'User-Agent': 'googlebot',
},
})

if (!response.ok) {
throw new Error(`HTTP error ${response.status}, ${tweetUrl}`)
}

const html = await response.text()
const $ = cheerio.load(html)

const ogDescription = $('meta[property="og:description"]').attr('content')

if (!ogDescription) {
throw new Error(`Could not extract tweet from html. ${html}`)
}
return ogDescription
}
138 changes: 130 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@
"@sentry/profiling-node": "^1.2.6",
"@sentry/remix": "^7.70.0",
"@types/cli-progress": "^3.11.5",
"@types/node-fetch": "^2.6.11",
"address": "^2.0.1",
"autoprefixer": "^10.4.16",
"bcryptjs": "^2.4.3",
"better-sqlite3": "^11.2.1",
"bloom-filters": "^3.0.1",
"cachified": "^3.5.4",
"chalk": "^5.3.0",
"cheerio": "^1.0.0",
"class-variance-authority": "^0.7.0",
"cli-progress": "^3.12.0",
"close-with-grace": "^1.2.0",
Expand Down Expand Up @@ -94,6 +96,7 @@
"moment": "^2.29.4",
"morgan": "^1.10.0",
"nock": "^13.5.4",
"node-fetch": "^2.7.0",
"openai": "^4.56.1",
"pino": "^9.2.0",
"pino-http": "^10.2.0",
Expand Down