Skip to content

Commit

Permalink
πŸš‘ Change Contribution logic (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
techinpark committed Jul 15, 2023
1 parent 907f589 commit f354a26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Sources/AppDelegate.swift
Expand Up @@ -524,11 +524,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

private func parseHtmltoData(html: String) -> [ContributeData] {
let isoDateFormatter = ISO8601DateFormatter()
isoDateFormatter.formatOptions = [.withFullDate]

do {
let doc: Document = try SwiftSoup.parse(html)
let rects: Elements = try doc.getElementsByTag(ParseKeys.rect)
let days: [Element] = rects.array().filter { $0.hasAttr(ParseKeys.date) }
let weekend = days.suffix(Consts.fetchCount)
let sortedDays = sortDaysByDate(days, with: isoDateFormatter)

let weekend = sortedDays.suffix(Consts.fetchCount)
let contributeDataList = weekend.map(mapFunction)
return contributeDataList

Expand All @@ -537,6 +542,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

private func sortDaysByDate(_ days: [Element], with dateFormatter: ISO8601DateFormatter) -> [Element] {
return days.sorted { (element1, element2) -> Bool in
guard let date1 = try? element1.attr(ParseKeys.date),
let date2 = try? element2.attr(ParseKeys.date),
let date1Value = dateFormatter.date(from: date1),
let date2Value = dateFormatter.date(from: date2) else {
return false
}
return date1Value < date2Value
}
}

private func parseHtmltoDataForCount(html: String) -> ContributeData {
do {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Consts/ParseKeys.swift
Expand Up @@ -9,5 +9,5 @@ import Foundation

enum ParseKeys {
static let date = "data-date"
static let rect = "rect"
static let rect = "td"
}

4 comments on commit f354a26

@Jeon0976
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ—…λ°μ΄νŠΈ 후에 μž”λ”” 이λͺ¨μ§€κ°€ 정상 μž‘λ™ μ•ˆν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.

@techinpark
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jeon0976 증상을 쒀더 μžμ„Ένžˆ 말씀해주싀 수 μžˆμ„κΉŒμš”?

@Jeon0976
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git id기반 컀밋정보λ₯Ό λͺ» λ°›μ•„μ˜€λŠ”κ²ƒκ°™μ•˜λŠ”λ° μˆ˜μ •ν•˜μ…¨κ΅°μš”
항상 잘 μ‚¬μš©ν•˜κ³ μžˆμŠ΅λ‹ˆλ‹€. κ°μ‚¬ν•©λ‹ˆλ‹€ μ„ μƒλ‹˜

@techinpark
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jeon0976 였 λ‹€ν–‰μž…λ‹ˆλ‹€ πŸ˜„ ν˜Ήμ‹œ λ™μž‘μ΄ μ΄μƒν•˜λ‹€ μ‹ΆμœΌμ‹œλ©΄ 이슈둜 μ˜¬λ €μ£Όμ„Έμš”!! κ°μ‚¬ν•©λ‹ˆλ‹€

Please sign in to comment.