From d9ec58b6022c0115b594354c639ceb1e0aeae8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fernando=2Eios=28=ED=8E=98=EB=A5=B4=EB=82=9C=EB=8F=84=29?= Date: Mon, 20 Nov 2023 20:27:27 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20Change=20Countribution=20parse?= =?UTF-8?q?=20logic=20(#32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/AppDelegate.swift | 20 ++++++++++++++++++-- Sources/Consts/ParseKeys.swift | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Sources/AppDelegate.swift b/Sources/AppDelegate.swift index 1a3355b..3cf93b8 100644 --- a/Sources/AppDelegate.swift +++ b/Sources/AppDelegate.swift @@ -530,11 +530,27 @@ class AppDelegate: NSObject, NSApplicationDelegate { do { let doc: Document = try SwiftSoup.parse(html) let rects: Elements = try doc.getElementsByTag(ParseKeys.rect) + let tooltips: Elements = try doc.getElementsByTag(ParseKeys.tooltip) let days: [Element] = rects.array().filter { $0.hasAttr(ParseKeys.date) } let sortedDays = sortDaysByDate(days, with: isoDateFormatter) - let weekend = sortedDays.suffix(Consts.fetchCount) - let contributeDataList = weekend.map(mapFunction) + + var tooltipsTextById = [String: String]() + for tooltip in tooltips.array() { + let id = try tooltip.attr("for") + let text = try tooltip.text() + tooltipsTextById[id] = text + } + + let updatedWeekend = weekend.map { element -> Element in + let id = element.id() + if let tooltipText = tooltipsTextById[id] { + try? element.text(tooltipText) + } + return element + } + + let contributeDataList = updatedWeekend.map(mapFunction) return contributeDataList } catch { diff --git a/Sources/Consts/ParseKeys.swift b/Sources/Consts/ParseKeys.swift index 715b5c3..5ec409c 100644 --- a/Sources/Consts/ParseKeys.swift +++ b/Sources/Consts/ParseKeys.swift @@ -10,4 +10,5 @@ import Foundation enum ParseKeys { static let date = "data-date" static let rect = "td" + static let tooltip = "tool-tip" }