improvments
This commit is contained in:
parent
c55a5263bf
commit
2171ca44bb
38
jrpg.ts
38
jrpg.ts
|
@ -12,10 +12,10 @@ function gettables(doc)
|
|||
return [...doc.getElementsByTagName("h2")].map(h2 => h2.id)
|
||||
}
|
||||
|
||||
function getcategory(doc, category, notes)
|
||||
function gettable(doc, table, notes)
|
||||
{
|
||||
const result = []
|
||||
const items = [...doc.getElementById(category).nextSibling.nextSibling.nextSibling.firstChild.children[0].children]
|
||||
const items = [...doc.getElementById(table).nextSibling.nextSibling.nextSibling.firstChild.children[0].children]
|
||||
const header = [...items.shift().children].map(h => h.textContent)
|
||||
items.forEach(elt => {
|
||||
const item = {}
|
||||
|
@ -24,7 +24,6 @@ function getcategory(doc, category, notes)
|
|||
{
|
||||
item[h] = columns[i].textContent
|
||||
})
|
||||
item.Notes = ""
|
||||
if (item.Name)
|
||||
{
|
||||
const sup = parseInt(item.Name.split(" ").pop())
|
||||
|
@ -48,7 +47,7 @@ function getnotes(doc)
|
|||
}
|
||||
return lastsup.parentElement.textContent.split("\n")
|
||||
.filter(i => i.length)
|
||||
.map(i => i.substr(3))
|
||||
.map(i => i.substr(3).trim())
|
||||
}
|
||||
|
||||
async function getpage(url)
|
||||
|
@ -60,20 +59,17 @@ async function getpage(url)
|
|||
const doc = getdompareser(html)
|
||||
const notes = getnotes(doc)
|
||||
const tables = gettables(doc)
|
||||
tables.forEach(category =>
|
||||
tables.forEach(table =>
|
||||
{
|
||||
result[category] = getcategory(doc, category, notes)
|
||||
result[table] = gettable(doc, table, notes)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
function format(equipment)
|
||||
function format(equipment, exclude)
|
||||
{
|
||||
const result = []
|
||||
const exclude = ["Found", "Sold", "Available", "Ft","Mr","Go"]
|
||||
|
||||
// todo: notes as footers instead of column
|
||||
// todo: put excludes in config
|
||||
// todo: invert available X mark
|
||||
// todo: remove a column if always empty
|
||||
|
||||
|
@ -98,7 +94,7 @@ function format(equipment)
|
|||
})
|
||||
})
|
||||
|
||||
// header
|
||||
// write header
|
||||
let line = ""
|
||||
Object.keys(columnsizes).forEach(columnname => {
|
||||
const size = columnsizes[columnname]
|
||||
|
@ -106,7 +102,7 @@ function format(equipment)
|
|||
})
|
||||
result.push(line)
|
||||
|
||||
// lines
|
||||
// write lines
|
||||
items.forEach(item => {
|
||||
let line = ""
|
||||
Object.keys(columnsizes).forEach(columnname => {
|
||||
|
@ -124,7 +120,7 @@ function format(equipment)
|
|||
|
||||
async function getdata(configname)
|
||||
{
|
||||
const pages = configs[configname]
|
||||
const pages = configs[configname].pages
|
||||
let result = {}
|
||||
const root = "https://mikesrpgcenter.com"
|
||||
for (const index in pages)
|
||||
|
@ -136,17 +132,19 @@ async function getdata(configname)
|
|||
return result
|
||||
}
|
||||
|
||||
function output(string)
|
||||
function output(stringresult, configname)
|
||||
{
|
||||
console.log(string)
|
||||
//console.log(stringresult)
|
||||
Deno.writeTextFile(configname + ".txt", stringresult)
|
||||
}
|
||||
|
||||
const configs = {
|
||||
ffantasy: ["weapons", "armor", "blackmagic", "whitemagic"],
|
||||
dw3: ["armor", "weapons"]
|
||||
ffantasy: { pages: ["weapons", "armor", "blackmagic", "whitemagic"], exclude: ["Found", "Sold", "Available", "Notes", "Cost", "Ni", "WM", "WW", "BM", "BW", "Th", "BB", "Ma"] },
|
||||
dw3: { pages: ["armor", "weapons"], exclude: [] },
|
||||
}
|
||||
|
||||
getdata("dw3")
|
||||
.then(format)
|
||||
.then(output)
|
||||
const configname = "ffantasy"
|
||||
|
||||
const data = await getdata(configname)
|
||||
const stringresult = format(data, configs[configname].exclude)
|
||||
output(stringresult, configname)
|
||||
|
|
Loading…
Reference in New Issue