Rewrite holiday merging
This commit is contained in:
@@ -188,20 +188,17 @@ extension KissConsole {
|
||||
|
||||
let result = try await account!.getHolyday(baseDate: day)
|
||||
do {
|
||||
let olds = try [HolidyResult.OutputDetail].readCsv(fromFile: KissConsole.holidayUrl)
|
||||
if let output = result.output {
|
||||
/// Merge current holidays and new holidays
|
||||
var recents = output.map { $0 }
|
||||
for old in olds {
|
||||
if let _ = recents.first(where: { $0.baseDate == old.baseDate }) {
|
||||
continue
|
||||
try output.mergeCsv(toFile: KissConsole.holidayUrl, merging: { this, file in
|
||||
var merged = this
|
||||
for old in file {
|
||||
if nil == this.first(where: { $0.baseDate == old.baseDate }) {
|
||||
merged.append(old)
|
||||
}
|
||||
}
|
||||
recents.append(old)
|
||||
}
|
||||
recents.sort(by: { $0.baseDate < $1.baseDate })
|
||||
|
||||
/// Write back with merged one
|
||||
try recents.writeCsv(toFile: KissConsole.holidayUrl, localized: localized)
|
||||
merged.sort(by: { $0.baseDate < $1.baseDate })
|
||||
return merged
|
||||
}, localized: localized)
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
|
||||
@@ -138,7 +138,7 @@ extension KissConsole {
|
||||
}
|
||||
merged.sort(by: { $0.stockBusinessDate > $1.stockBusinessDate })
|
||||
return merged
|
||||
}, localized: false)
|
||||
}, localized: localized)
|
||||
}
|
||||
}
|
||||
try await Task.sleep(nanoseconds: 1_000_000_000 / PreferredShortsTPS)
|
||||
|
||||
Reference in New Issue
Block a user