Add data-fetch tool used to fetch unknown spell metadata from wowhead <3

This commit is contained in:
Melvin Valster
2019-07-25 15:50:36 +02:00
parent cf6c4ea7b1
commit 256118fd1a
9 changed files with 8330 additions and 11 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ import {
import { talentsBySpec } from '../data/talents'
import { classByName } from '../data/classes'
import { History } from 'history'
import { debugPrintKnown } from '../lib/debug'
// import { debugPrintKnown } from '../lib/debug'
import { Link } from 'react-router-dom';
interface Props {
@@ -59,7 +59,7 @@ export class Calculator extends React.PureComponent<Props> {
this.setState({ knownTalents: newKnownTalents })
// Debug
debugPrintKnown(newKnownTalents)
// debugPrintKnown(newKnownTalents)
}
render() {
+8144
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -204,7 +204,6 @@ export function decodeKnownTalents(pointString: string, className: string): Map<
for (let i = 0; i < parts.length; i++) {
const specId = specs[i]
const specPointStr = parts[i]
console.log(specPointStr, { specId })
const talents = talentsBySpecArray[specId].sort(SORT_TALENTS)
for (let y = 0; y < specPointStr.length; y++) {
+65
View File
@@ -0,0 +1,65 @@
// import '../src/types'
import { talentsById } from '../data/talents'
import fetch from 'node-fetch'
import fs from 'fs'
import cheerio from 'cheerio'
import spells from '../data/spells.json'
const getRankFromTooltip = (spellId: number, tooltip: string): number | null => {
const matches = tooltip.match(/Rank (\d)/)
if (!matches) {
console.warn(`Spell ${spellId}: No rank found in tooltip: \n\t`, tooltip)
return null
}
return parseInt(matches[1], 10)
}
const getUnknownSpellIds = (): number[] => {
const allSpellIds = Object.values(talentsById).reduce((reduction, talent: TalentData) => {
reduction = [...reduction, ...talent.ranks]
return reduction
}, [])
return allSpellIds.filter(spellId => !spells[spellId.toString()])
}
export const fetchSpellData = async () => {
const unknownSpellIds = getUnknownSpellIds()
console.log(`Fetching spell data for ${unknownSpellIds.length} unknown spells`)
const promises = unknownSpellIds.slice(0, 20).map(async (spellId): Promise<boolean> => {
if (!spells[spellId.toString()]) {
console.log(`Loading data for unknown spell: ${spellId}`)
const res = await fetch(`https://classic.wowhead.com/tooltip/spell/${spellId}`)
if (res.status !== 200) {
console.error(`Could not find data for spell: ${spellId}`)
return null
}
const json: any = await res.json()
const $ = cheerio.load(json.tooltip)
const spell: SpellData = {
name: json.name,
icon: json.icon,
rank: getRankFromTooltip(spellId, json.tooltip),
description: $('.q').text()
}
spells[spellId.toString()] = spell
return true
}
})
await Promise.all(promises)
fs.writeFileSync('./src/data/spells.json', JSON.stringify(spells, null, 2))
if (getUnknownSpellIds().length > 0) {
console.log('--- We have more unknown spells: ', getUnknownSpellIds().length)
fetchSpellData()
}
}
fetchSpellData()
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es6",
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"../types.d.ts"
],
"exclude": [
"../src/lib/foo.ts"
]
}
+9 -1
View File
@@ -5,6 +5,14 @@ interface TalentTree {
talents: Talent[]
}
interface SpellData {
id?: number
name: string
rank: number
icon: string
description: string
}
interface ClassData {
id: number
name: string
@@ -41,4 +49,4 @@ interface Talent {
prerequisite?: [number, number] | number // [row, column] OR index
}
type TalentClickHandler = (specId: number, talentId: number, modifier: 1 | -1) => void
type TalentClickHandler = (specId: number, talentId: number, modifier: 1 | -1) => void