// // Downloader.swift // TournamentStats // // Created by Laurent Morvillier on 02/10/2021. // Copyright © 2021 Stax River. All rights reserved. // import Foundation import RealmSwift class Downloader { struct TS { var id: String var date: String } static func downloadWSOPResults() { let infos = [ TS(id: "19728", date: "02/10/2021"), TS(id: "19729", date: "03/10/2021"), TS(id: "19730", date: "02/10/2021"), TS(id: "19732", date: "04/10/2021"), TS(id: "19733", date: "05/10/2021"), TS(id: "19731", date: "06/10/2021"), TS(id: "19734", date: "06/10/2021"), TS(id: "19926", date: "06/10/2021"), TS(id: "19927", date: "06/10/2021"), TS(id: "19737", date: "06/10/2021"), TS(id: "19735", date: "07/10/2021"), ] for info in infos { downloadWSOPResults(tournamentInfo: info) } // for i in 19728...19732 { // DispatchQueue.global(qos: .utility).async { // // downloadWSOPResults(tournamentId: "\(i)") // // } // } } fileprivate static func downloadWSOPResults(tournamentInfo: TS) { print("Importing tournament \(tournamentInfo.id)") guard let url = URL(string: "https://www.wsop.com/tournaments/results/?aid=2&grid=4865&tid=\(tournamentInfo.id)&rr=5") else { return } let realm = try! Realm() let nf = NumberFormatter() nf.numberStyle = .decimal nf.locale = Locale.init(identifier: "en_US") nf.groupingSeparator = "," do { let string = try String(contentsOf: url) let infos = string.slice(from: "