完成数据清洗

This commit is contained in:
zhushenwudi 2025-01-14 23:16:21 +08:00
parent da848c9128
commit a070f82853
4 changed files with 73 additions and 48 deletions

View File

@ -15,7 +15,7 @@ dependencies {
implementation('org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1') implementation('org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1')
implementation 'org.jsoup:jsoup:1.18.3' implementation 'org.jsoup:jsoup:1.18.3'
implementation "org.ktorm:ktorm-core:4.1.1" implementation "org.ktorm:ktorm-core:4.1.1"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'
implementation("mysql:mysql-connector-java:8.0.33") implementation("mysql:mysql-connector-java:8.0.33")
} }

View File

@ -24,20 +24,21 @@ suspend fun main(args: Array<String>) {
val database = Database.connect( val database = Database.connect(
url = "jdbc:mysql://localhost:3306/sif_card", url = "jdbc:mysql://localhost:3306/sif_card",
driver = "com.mysql.jdbc.Driver", driver = "com.mysql.cj.jdbc.Driver",
user = "root", user = "root",
password = "" password = ""
) )
cardList.forEach { card -> cardList.forEach { card ->
database.useTransaction { database.useTransaction {
val count = database var id = -1
.from(TCard) for (row in database.from(TCard).select().where { TCard.name eq card.name }) {
.select() row[TCard.characterName]?.let { characterName ->
.where { TCard.name eq card.name } if (characterName.isNotEmpty()) {
.totalRecordsInAllPages return@forEach
if (count > 0) { }
return@forEach id = row[TCard.id]!!
}
} }
gameList.find { gameCh -> gameCh.name.contains(card.name) }?.let { gameCh -> gameList.find { gameCh -> gameCh.name.contains(card.name) }?.let { gameCh ->
@ -89,29 +90,53 @@ suspend fun main(args: Array<String>) {
tables[4].select(".mu__table--row2").apply { tables[4].select(".mu__table--row2").apply {
card.specialSkillInfo = select(".mu__table--col1").text() card.specialSkillInfo = select(".mu__table--col1").text()
} }
} } ?: run { return@forEach }
println(card) println(card)
database.insert(TCard) { if (id == -1) {
set(it.name, card.name) database.insert(TCard) {
set(it.characterId, card.characterId) set(it.name, card.name)
set(it.characterName, card.characterName) set(it.characterId, card.characterId)
set(it.type, card.type) set(it.characterName, card.characterName)
set(it.rarity, card.rarity) set(it.type, card.type)
set(it.maxLevel, card.maxLevel) set(it.rarity, card.rarity)
set(it.maxHp, card.maxHp) set(it.maxLevel, card.maxLevel)
set(it.smile, card.smile) set(it.maxHp, card.maxHp)
set(it.pure, card.pure) set(it.smile, card.smile)
set(it.cool, card.cool) set(it.pure, card.pure)
set(it.illustId, card.illustId) set(it.cool, card.cool)
set(it.evolveIllustId, card.evolveIllustId) set(it.illustId, card.illustId)
set(it.group, card.group) set(it.evolveIllustId, card.evolveIllustId)
set(it.team, card.team) set(it.group, card.group)
set(it.date, card.date) set(it.team, card.team)
set(it.centerSkillName, card.centerSkillName) set(it.date, card.date)
set(it.centerSkillInfo, card.centerSkillInfo) set(it.centerSkillName, card.centerSkillName)
set(it.specialSkillName, card.specialSkillName) set(it.centerSkillInfo, card.centerSkillInfo)
set(it.specialSkillInfo, card.specialSkillInfo) set(it.specialSkillName, card.specialSkillName)
set(it.specialSkillInfo, card.specialSkillInfo)
}
} else {
database.update(TCard) {
set(it.characterName, card.characterName)
set(it.type, card.type)
set(it.rarity, card.rarity)
set(it.maxLevel, card.maxLevel)
set(it.maxHp, card.maxHp)
set(it.smile, card.smile)
set(it.pure, card.pure)
set(it.cool, card.cool)
set(it.illustId, card.illustId)
set(it.evolveIllustId, card.evolveIllustId)
set(it.group, card.group)
set(it.team, card.team)
set(it.date, card.date)
set(it.centerSkillName, card.centerSkillName)
set(it.centerSkillInfo, card.centerSkillInfo)
set(it.specialSkillName, card.specialSkillName)
set(it.specialSkillInfo, card.specialSkillInfo)
where { TCard.id eq id }
}
} }
} }

View File

@ -457,7 +457,7 @@
{ {
"id": 10050010, "id": 10050010,
"characterId": 1005, "characterId": 1005,
"name": "μ'の元気印", "name": "μ'sの元気印",
"illustId": "01005_0010_00", "illustId": "01005_0010_00",
"evolveIllustId": "01005_0010_01" "evolveIllustId": "01005_0010_01"
}, },

View File

@ -1,7 +1,7 @@
[ [
{ {
"url": "https://gamerch.com/lovelivesif2/767609", "url": "https://gamerch.com/lovelivesif2/767609",
"name": "Aquoursと申しますわ黒澤ダイヤ", "name": "Aqoursと申しますわ黒澤ダイヤ",
"rarity": 2 "rarity": 2
}, },
{ {
@ -31,17 +31,17 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/758859", "url": "https://gamerch.com/lovelivesif2/758859",
"name": "μ’sと私矢澤にこ", "name": "µ'sと私矢澤にこ",
"rarity": 1 "rarity": 1
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/811888", "url": "https://gamerch.com/lovelivesif2/811888",
"name": "μ’sのクリスマス園田海未", "name": "µ'sのクリスマス園田海未",
"rarity": 1 "rarity": 1
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/748012", "url": "https://gamerch.com/lovelivesif2/748012",
"name": "μ’sへの想い小泉花陽", "name": "µ'sへの想い小泉花陽",
"rarity": 1 "rarity": 1
}, },
{ {
@ -121,7 +121,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/748007", "url": "https://gamerch.com/lovelivesif2/748007",
"name": "[いらっしゃませ♪]南ことり", "name": "[いらっしゃませ♪]南ことり",
"rarity": 1 "rarity": 1
}, },
{ {
@ -781,7 +781,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/767340", "url": "https://gamerch.com/lovelivesif2/767340",
"name": "[サプライズBBQ]宮下愛", "name": "[サプライズ]宮下愛",
"rarity": 1 "rarity": 1
}, },
{ {
@ -1536,7 +1536,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/815232", "url": "https://gamerch.com/lovelivesif2/815232",
"name": "も方便]鬼塚夏美", "name": "も方便]鬼塚夏美",
"rarity": 1 "rarity": 1
}, },
{ {
@ -1551,7 +1551,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/748053", "url": "https://gamerch.com/lovelivesif2/748053",
"name": "[地上230メートル]桜小路きな子", "name": "[地上メートル]桜小路きな子",
"rarity": 1 "rarity": 1
}, },
{ {
@ -1691,7 +1691,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/767462", "url": "https://gamerch.com/lovelivesif2/767462",
"name": "[好きなった内浦]桜内梨子", "name": "[好きなった内浦]桜内梨子",
"rarity": 3 "rarity": 3
}, },
{ {
@ -1801,7 +1801,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/767420", "url": "https://gamerch.com/lovelivesif2/767420",
"name": "いを馳せて]高海千歌", "name": "いを馳せて]高海千歌",
"rarity": 3 "rarity": 3
}, },
{ {
@ -2081,7 +2081,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/767417", "url": "https://gamerch.com/lovelivesif2/767417",
"name": "[水泳日和]高海千歌", "name": "[水泳日和]高海千歌",
"rarity": 3 "rarity": 3
}, },
{ {
@ -2116,7 +2116,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/818426", "url": "https://gamerch.com/lovelivesif2/818426",
"name": "[海眺める初日の出]高海千歌", "name": "[海眺める初日の出]高海千歌",
"rarity": 1 "rarity": 1
}, },
{ {
@ -2391,7 +2391,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/815221", "url": "https://gamerch.com/lovelivesif2/815221",
"name": "[笑う門には福来る]嵐千砂都", "name": "[笑う門には福来る]嵐千砂都",
"rarity": 1 "rarity": 1
}, },
{ {
@ -2416,7 +2416,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/766205", "url": "https://gamerch.com/lovelivesif2/766205",
"name": "[紅のかざぐるま]優木せつ菜", "name": "[紅のかざぐるま]優木せつ菜",
"rarity": 2 "rarity": 2
}, },
{ {
@ -2601,7 +2601,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/823803", "url": "https://gamerch.com/lovelivesif2/823803",
"name": "[試食挑戦者募集]若菜四季", "name": "[試食挑戦者募集]若菜四季",
"rarity": 2 "rarity": 2
}, },
{ {
@ -2636,7 +2636,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/813588", "url": "https://gamerch.com/lovelivesif2/813588",
"name": "やかな街!]高海千歌", "name": "にぎやかな街!]高海千歌",
"rarity": 2 "rarity": 2
}, },
{ {
@ -2746,7 +2746,7 @@
}, },
{ {
"url": "https://gamerch.com/lovelivesif2/759114", "url": "https://gamerch.com/lovelivesif2/759114",
"name": "[間違えないで!]南ことり", "name": "[間違えないで!]南ことり",
"rarity": 1 "rarity": 1
}, },
{ {