45 lines
1.1 KiB
Swift
45 lines
1.1 KiB
Swift
//
|
|
// StatusBarController.swift
|
|
// LiquipediaMenu
|
|
//
|
|
// Created by Felix Förtsch on 08.10.18.
|
|
// Copyright © 2018 Felix Förtsch. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
import SwiftyJSON
|
|
|
|
class StatusBarController: NSObject {
|
|
|
|
let baseURL = "https://liquipedia.net/"
|
|
let game = "dota2"
|
|
let query = "/api.php?action=parse&page=Liquipedia:Upcoming_and_ongoing_matches&format=json&prop=text"
|
|
|
|
var html = ""
|
|
|
|
func constructURL(baseURL: String, game: String, query: String) -> String {
|
|
return baseURL + game + query
|
|
}
|
|
|
|
func fetch(url: String) {
|
|
|
|
DispatchQueue.global().async {
|
|
|
|
[unowned self] in
|
|
if let url = URL(string: url) {
|
|
if let data = try? String(contentsOf: url) {
|
|
let json = JSON(parseJSON: data)
|
|
self.html = self.extractHTML(json: json)
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func extractHTML(json: JSON) -> String {
|
|
return json["parse"]["text"].stringValue
|
|
}
|
|
|
|
}
|