-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-wordlist.js
48 lines (42 loc) · 1.09 KB
/
update-wordlist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const fetch = require('node-fetch')
const fs = require('fs')
const fetchJS = async () => {
const urlBase =
'https://www.nytimes.com/games/wordle/'
const url = urlBase + 'index.html'
try {
const html = await (await fetch(url)).text()
const scriptNames = [
...html.matchAll(
/\<script [^>]*?src="(.+?(?<=\/)[\w.]+?\.js)"[^>]*?\>/sg
)
].map(x => x[1])
const list = (await Promise.all(
scriptNames.map(async x => (await fetch(x)).text())
))
.map(s =>
s.match(/\[\s*["'](?:CIGAR|AAHED)[^\]]+\]/i)
)
.filter(x => !!x)
.map(x => JSON.parse(x[0].toUpperCase()))[0]
const cigarIdx = list.indexOf('CIGAR')
return [
list.slice(0, cigarIdx),
list.slice(cigarIdx)
].map(x => x.join('\n'))
} catch (err) {
console.error(err)
}
}
fetchJS().then(([allWords, puzzleWords]) => {
fs.writeFileSync(
'./data/puzzle-words.txt',
puzzleWords
)
fs.writeFileSync(
'./data/all-words.txt',
allWords
)
})
.then(() => console.log('Success'))
.catch(err => console.error(err))