<commit_before>//
//  Hearthstonetopdecks.swift
//  HSTracker
//
//  Created by <NAME> on 29/08/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import Kanna
import CleanroomLogger

struct HearthstoneTopDecks: HttpImporter {

    var siteName: String {
        return "Hearthstonetopdecks"
    }

    var handleUrl: String {
        return "hearthstonetopdecks\\.com\\/decks"
    }

    var preferHttps: Bool {
        return true
    }

    func loadDeck(doc: HTMLDocument, url: String) -> (Deck, [Card])? {
        guard let nameNode = doc.at_xpath("//h1[contains(@class, 'entry-title')]"),
            let deckName = nameNode.text else {
                Log.error?.message("Deck name not found")
                return nil
        }
        Log.verbose?.message("Got deck name \(deckName)")

        let xpath = "//div[contains(@class, 'deck-info')]/a[contains(@href, 'deck-class') ]"
        guard let classNode = doc.at_xpath(xpath),
            let className = classNode.text?.trim(),
            let playerClass = CardClass(rawValue: className.lowercased()) else {
                Log.error?.message("Class not found")
                return nil
        }
        Log.verbose?.message("Got class \(playerClass)")

        let deck = Deck()
        deck.playerClass = playerClass
        deck.name = deckName

        var cards: [Card] = []
        let cardNodes = doc.xpath("//*[contains(@class, 'deck-class')]/li/a")
        for cardNode in cardNodes {
            if let cardName = cardNode.at_xpath("span[@class='card-name']")?.text,
                let cardcountstr = cardNode.at_xpath("span[@class='card-count']")?.text,
                let count = Int(cardcountstr) {

                // Hearthstonetopdeck sport several cards with wrong capitalization
                // (e.g. N'Zoth)
                let fixedCardName = cardName.trim().replace("’", with: "'")
                if let card = Cards.by(englishNameCaseInsensitive: fixedCardName) {
                    card.count = count
                    Log.verbose?.message("Got card \(card)")
                    cards.append(card)
                }<commit_msg>Changed xpaths to match windows tracker<commit_after>//
//  Hearthstonetopdecks.swift
//  HSTracker
//
//  Created by <NAME> on 29/08/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import Kanna
import CleanroomLogger

struct HearthstoneTopDecks: HttpImporter {

    var siteName: String {
        return "Hearthstonetopdecks"
    }

    var handleUrl: String {
        return "hearthstonetopdecks\\.com\\/decks"
    }

    var preferHttps: Bool {
        return true
    }

    func loadDeck(doc: HTMLDocument, url: String) -> (Deck, [Card])? {
        guard let nameNode = doc.at_xpath("//h1[contains(@class, 'entry-title')]"),
            let deckName = nameNode.text else {
                Log.error?.message("Deck name not found")
                return nil
        }
        Log.verbose?.message("Got deck name \(deckName)")

        let xpath = "//div[contains(@class, 'deck-info')]/a[contains(@href, 'deck-class') ]"
        guard let classNode = doc.at_xpath(xpath),
            let className = classNode.text?.trim(),
            let playerClass = CardClass(rawValue: className.lowercased()) else {
                Log.error?.message("Class not found")
                return nil
        }
        Log.verbose?.message("Got class \(playerClass)")

        let deck = Deck()
        deck.playerClass = playerClass
        deck.name = deckName

        var cards: [Card] = []
        let cardNodes = doc.xpath("//*[contains(@class, 'deck-class')]/li")
        for cardNode in cardNodes {
            if let cardName = cardNode.at_xpath(".//a/span[@class='card-name']")?.text,
                let cardcountstr = cardNode.at_xpath("span[@class='card-count']")?.text,
                let count = Int(cardcountstr) {

                // Hearthstonetopdeck sport several cards with wrong capitalization
                // (e.g. N'Zoth)
                let fixedCardName = cardName.trim().replace("’", with: "'")
                if let card = Cards.by(englishNameCaseInsensitive: fixedCardName) {
                    card.count = count
                    Log.verbose?.message("Got card \(card)")
                    cards.append(card)
                }
{'fraction_non_alphanumeric': 0.12981323495503805, 'fraction_numerical': 0.005072630850818538, 'mean_word_length': 1.9979267449896336, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1457539', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1240, 'n_words': 289}