Skip to content

Commit

Permalink
research materials
Browse files Browse the repository at this point in the history
  • Loading branch information
ManApart committed Sep 15, 2024
1 parent cf1a8b5 commit 5e8fe61
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 5 deletions.
145 changes: 145 additions & 0 deletions src/jsMain/resources/research-wiki-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,21 @@
"perks": {
},
"materials": [
{
"name": "Bread",
"count": 3,
"url": "/wiki/Starfield:Bread"
},
{
"name": "Red Meat",
"count": 2,
"url": "/wiki/Starfield:Red_Meat"
},
{
"name": "Cheese",
"count": 2,
"url": "/wiki/Starfield:Cheese"
}
]
},
{
Expand All @@ -427,6 +442,31 @@
"Gastronomy": 1
},
"materials": [
{
"name": "Spice",
"count": 5,
"url": "/wiki/Starfield:Spice"
},
{
"name": "Cheese",
"count": 5,
"url": "/wiki/Starfield:Cheese"
},
{
"name": "Egg",
"count": 5,
"url": "/wiki/Starfield:Egg"
},
{
"name": "Butter",
"count": 5,
"url": "/wiki/Starfield:Butter"
},
{
"name": "Poultry",
"count": 5,
"url": "/wiki/Starfield:Poultry"
}
]
},
{
Expand All @@ -441,6 +481,36 @@
"Gastronomy": 2
},
"materials": [
{
"name": "Spice",
"count": 10,
"url": "/wiki/Starfield:Spice"
},
{
"name": "Nutrient",
"count": 20,
"url": "/wiki/Starfield:Nutrient"
},
{
"name": "Beer",
"count": 10,
"url": "/wiki/Starfield:Beer"
},
{
"name": "Poultry",
"count": 10,
"url": "/wiki/Starfield:Poultry"
},
{
"name": "Dairy",
"count": 10,
"url": "/wiki/Starfield:Dairy"
},
{
"name": "Egg",
"count": 10,
"url": "/wiki/Starfield:Egg"
}
]
},
{
Expand All @@ -453,6 +523,21 @@
"perks": {
},
"materials": [
{
"name": "Spice",
"count": 2,
"url": "/wiki/Starfield:Spice"
},
{
"name": "Fiber",
"count": 3,
"url": "/wiki/Starfield:Fiber"
},
{
"name": "Water",
"count": 3,
"url": "/wiki/Starfield:Water"
}
]
},
{
Expand All @@ -467,6 +552,31 @@
"Gastronomy": 1
},
"materials": [
{
"name": "Aromatic",
"count": 5,
"url": "/wiki/Starfield:Aromatic"
},
{
"name": "Benzene",
"count": 5,
"url": "/wiki/Starfield:Benzene"
},
{
"name": "Spice",
"count": 5,
"url": "/wiki/Starfield:Spice"
},
{
"name": "Metabolic Agent",
"count": 10,
"url": "/wiki/Starfield:Metabolic_Agent"
},
{
"name": "Tranquilitea Sunray",
"count": 5,
"url": "/wiki/Starfield:Tranquilitea_Sunray"
}
]
},
{
Expand All @@ -479,6 +589,21 @@
"perks": {
},
"materials": [
{
"name": "Aromatic",
"count": 2,
"url": "/wiki/Starfield:Aromatic"
},
{
"name": "Alkanes",
"count": 2,
"url": "/wiki/Starfield:Alkanes"
},
{
"name": "Spice",
"count": 3,
"url": "/wiki/Starfield:Spice"
}
]
},
{
Expand All @@ -493,6 +618,26 @@
"Gastronomy": 1
},
"materials": [
{
"name": "Aromatic",
"count": 10,
"url": "/wiki/Starfield:Aromatic"
},
{
"name": "Spice",
"count": 10,
"url": "/wiki/Starfield:Spice"
},
{
"name": "Liquor",
"count": 5,
"url": "/wiki/Starfield:Liquor"
},
{
"name": "Can-Uck! Poutine",
"count": 5,
"url": "/wiki/Starfield:Can-Uck!_Poutine"
}
]
},
{
Expand Down
23 changes: 18 additions & 5 deletions src/jvmMain/kotlin/wikiScraper/ResearchWikiScraper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ fun main() {
}

private fun parseResearch(page: Document): List<ResearchProject> {


return page.select(".wikitable").flatMapIndexed { categoryIndex: Int, table: Element? ->
val category = ResearchCategory.entries[categoryIndex]
table!!.select("tr").drop(1).map { row ->
Expand All @@ -38,7 +36,11 @@ private fun parseResearch(page: Document): List<ResearchProject> {
val perkRow = if (colCount == 5) 2 else 1
val perks = row.selectTd(perkRow)?.text()?.toRankMap() ?: mapOf()
val description = row.selectTdClean(4) ?: ""
val matRow = if (colCount == 5) 3 else 2
val matRow = when {
category == ResearchCategory.FOOD_AND_DRINK -> 3
colCount == 5 -> 3
else -> 2
}
val materials = row.selectTd(matRow).parseMaterials()

ResearchProject(name, category, rank, description, preReqs, perks, materials)
Expand Down Expand Up @@ -75,7 +77,18 @@ private fun Element?.parseMaterials(): List<Material> {
val rawAmounts2 = this.text().split(" ", ",").mapNotNull { it.toIntOrNull() }
val amounts = if (rawAmounts1.size > rawAmounts2.size) rawAmounts1 else rawAmounts2

return select("a").mapIndexed { i, a ->
Material(a.text(), amounts[i], a.attr("href"))
val links = select("a")
return if (links.isNotEmpty()) {
links.mapIndexed { i, a ->
Material(a.text(), amounts[i], a.attr("href"))
}
} else {
val names = html().split("<br>").filter { it.isNotEmpty() }
.map { it.substring(0, it.indexOf("x")).trim() }

names.mapIndexed { i, name ->
val url = "/wiki/Starfield:${name.replace(" ", "_")}"
Material(name, amounts[i], url)
}
}
}

0 comments on commit 5e8fe61

Please sign in to comment.