Skip to content

Commit

Permalink
🚑 Change Countribution parse logic (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
techinpark authored Nov 20, 2023
1 parent 238d3af commit d9ec58b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Sources/Consts/ParseKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import Foundation
enum ParseKeys {
static let date = "data-date"
static let rect = "td"
static let tooltip = "tool-tip"
}

0 comments on commit d9ec58b

Please sign in to comment.