This is a simple package only to retrieve boardgames from BigGameGeek.
Scrap IDs from website and go to XML API then transforming it to JSON :)
It works only with ES Modules, hence you need set "type": "module"
inside your package.json
It has four different functions which allow you to:
- Parse all gameIds from BGG boardgames webpage -
parseGameIds(config)
- Get boardgames by IDs in XML -
getBoardgamesByIdsXML(idsInString)
- Get boardgames by IDs in JS object -
getOriginalBoardgames(idsInString)
- Get mapped JS object by IDs with camelCase (Also removed fields such as poll) -
getMappedOriginalBoardgames(idsInString)
npm install bgg-boardgames-xml-json
Set type to "module" in package.json
{
"type": "module"
}
yourfile.js
import { parseGameIds, getBoardgamesByIdsXML, getOriginalBoardgames, getMappedOriginalBoardgames } from 'bgg-boardgames-xml-json'
// use functions
Under the hood it opens the browser, hence this operation is long-term
const config = {
login: 'YourBggLogin',
password: 'YourBggPassword',
lastPageToParse: 3 // Three pages will be pared
}
const ids = await parseGameIds(config) // '224517,161936, ...'
Be aware that one page returns 100 boardgames
We can use parseGameIds with getBoardGamesByIdsXML
const ids = await parseGameIds(config) // '224517,161936'
const xml = await getBoardgamesByIdsXML(ids) // <boardgame>...</boardgame>
Or we can pass the string itself
const xml = await getBoardgamesByIdsXML('224517,161936') // <boardgame>...</boardgame>
Same we can use parseGameIds with getOriginalBoardgames
const ids = await parseGameIds(config) // '224517,161936'
const originalBoardgames = await getOriginalBoardgames(ids) // { boardgame: { boardgame: [] } }
Or we can pass the string itself
const originalBoardgames = await getOriginalBoardgames('224517,161936') // { boardgame: { boardgame: [] } }
Same we can use parseGameIds with getMappedOriginalBoardgames
const ids = await parseGameIds(config) // '224517,161936'
const mappedBoardgames = await getMappedOriginalBoardgames(ids) // { boardgame: [] }
Or we can pass the string itself
const mappedBoardgames = await getMappedOriginalBoardgames('224517,161936') // { boardgame: [] }
import { parseGameIds, getBoardgamesByIdsXML, getOriginalBoardgames, getMappedOriginalBoardgames } from 'bgg-boardgames-xml-json'
import fs from 'fs/promises'
const config = {
login: 'YourLogin',
password: 'YourPassword',
lastPageToParse: 3
}
// Login to BGG, Run chromium, navigate urls to get IDs
const ids = await parseGameIds(config)
// Get XML and save it to file
const xml = await getBoardgamesByIdsXML(ids)
await fs.writeFile('./boardgames.xml', xml)
// Get AS IS js object converted from XML and save it to file as JSON
const originalBoardgames = await getOriginalBoardgames(ids)
await fs.writeFile('./boardgames-original.json', JSON.stringify(originalBoardgames))
// Get mapped js object converted from XML and save it to file as JSON
const mappedOriginalBoardgames = await getMappedOriginalBoardgames(ids)
await fs.writeFile('./boardgames-mapped.json', JSON.stringify(mappedOriginalBoardgames))