Skip to content

Instantly share code, notes, and snippets.

@hubgit
Last active January 20, 2022 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hubgit/20447df48dd4936926ed2416186a8fe0 to your computer and use it in GitHub Desktop.
Save hubgit/20447df48dd4936926ed2416186a8fe0 to your computer and use it in GitHub Desktop.
Fetch and parse Wordle lines from recent tweets
import fs from 'fs-extra'
import Twitter from 'twitter-v2'
const n = '213'
const query = `"wordle ${n}" -RT`
const auth = fs.readJSONSync('auth-node.json')
const client = new Twitter(auth)
const output = fs.createWriteStream(`data/wordle-${n}.txt`)
const params = {
query,
max_results: 100,
}
const filterRe = new RegExp(`Wordle\\s+${n}\\s+[1-6]/6`)
const wordRe = /(^|\s)(?<word>[⬛🟨🟩]{5})($|\s)/umg
do {
const { data, meta } = await client.get('tweets/search/recent', params)
console.log({ data, meta })
for (const item of data) {
if (item.text.includes('@')) {
continue
}
if (!filterRe.test(item.text)) {
continue
}
const cleanText = item.text.replaceAll('⬜', '⬛').replaceAll('⬛️', '⬛')
console.log(cleanText)
let match
const words = []
while (match = wordRe.exec(cleanText)) {
words.push(match.groups.word)
}
if (words.length) {
console.log(words)
if (words.indexOf('🟩🟩🟩🟩🟩') !== words.length - 1) {
continue
}
output.write(words.join(' '))
output.write('\n')
}
}
params.next_token = meta.next_token
await new Promise((resolve) => setTimeout(resolve, 1000))
} while (params.next_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment