Skip to content

Commit

Permalink
parse wiki :P
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jun 24, 2024
1 parent 11d5fb7 commit 1625e0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/api/squaremap/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ export const parseTowns = async(res: SquaremapMarkerset, removeAccents = false)
}

const townName = parsedTooltip[0]
const nationName = parsedTooltip[1] ? formatString(parsedTooltip[1], removeAccents) : "No Nation"

const town: SquaremapTown = {
name: formatString(townName, removeAccents),
nation: parsedTooltip[1] ? formatString(parsedTooltip[1], removeAccents) : "No Nation",
nation: nationName,
mayor: parseInfoString(info[1]),
assistants,
residents,
Expand All @@ -106,6 +107,14 @@ export const parseTowns = async(res: SquaremapMarkerset, removeAccents = false)
}
}

//#region Parse wiki and add to town if it exists.
const match = info[0].match(/href="([^"]*)"/)
const wikiLink = match ? match[1] : null

if (wikiLink)
town['wiki'] = wikiLink
//#endregion

towns.push(town)
}

Expand Down Expand Up @@ -148,7 +157,7 @@ export const parseNations = async(towns: SquaremapTown[]) => {
raw[nationName].towns?.push(town.name)

if (town.flags.capital) {
//if (town.wiki) raw[nationName].wiki = town.wiki
if (town.wiki) raw[nationName].wiki = town.wiki

raw[nationName].king = town.mayor
raw[nationName].capital = {
Expand Down
3 changes: 1 addition & 2 deletions tests/squaremap/nations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ describe('[Squaremap/Aurora] Nations', () => {
const nation = await Aurora.Nations.get('madagascar')

expect(nation).toBeDefined()
expectTypeOf(nation).not.toEqualTypeOf<Error>()
expectTypeOf(nation).not.toEqualTypeOf<Error>
assertType<Nation | Nation[]>(nation)

expect(nation.name).toBe('Madagascar')
//console.log(nation.residents.length)
})
})
2 changes: 1 addition & 1 deletion tests/squaremap/towns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('[Squaremap/Aurora] Towns', () => {
})

it('can get single town', async () => {
const town = await Aurora.Towns.get('brisbane')
const town = await Aurora.Towns.get('Morven')

expect(town).toBeTruthy()
expect(town).toBeDefined()
Expand Down

0 comments on commit 1625e0f

Please sign in to comment.