Added fetching scripts
This commit is contained in:
19
scripts/utils/retrieveRecipes.ts
Normal file
19
scripts/utils/retrieveRecipes.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import fetch from 'node-fetch'
|
||||
import { parse } from 'node-html-parser'
|
||||
import { UnfetchedEntity } from './types'
|
||||
|
||||
export const retrieveRecipes = async (lang?: string) => {
|
||||
const res = await fetch(
|
||||
`https://wiki.factorio.com/Materials_and_recipes${lang ? `/${lang}` : ''}`
|
||||
)
|
||||
const html = await res.text()
|
||||
const root = parse(html)
|
||||
const icons = root.querySelectorAll('.tab > div > div.factorio-icon > a')
|
||||
return icons
|
||||
.map(icon => ({
|
||||
name: icon.attrs.title,
|
||||
href: icon.attrs.href,
|
||||
image: icon.querySelector('img')?.attrs.src
|
||||
}))
|
||||
.filter((entity): entity is UnfetchedEntity => !!(entity.href && entity.name && entity.image))
|
||||
}
|
||||
Reference in New Issue
Block a user