示例#1
0
def decks_from_smashgg(bracket_url, dest, ordered=False, code_dest=None):
    if ordered:
        setup_dirs(dest)
    deck_dict = {}
    html = requests.get(bracket_url).text
    parser = SmashHTMLParser()
    parser.feed(html)
    data = json.loads(
        parser.extracted)['dehydratedState']['context']['dispatcher']['stores']
    hero_map = {
        617: 671,
        618: 274,
        619: 31,
        620: 637,
        621: 813,
        622: 930,
        623: 1066,
        624: 893,
        625: 7
    }
    reverse_map = {}
    for _, card in data['CardStore']['card'].items():
        reverse_map[int(card['id'])] = int(card['externalId'])
    for _, deck in data['CardDeckStore']['cardDeck'].items():
        name = data['EntrantStore']['entrants'][str(deck['entrantId'])]['name']
        cards = {}
        for card in deck['cardIds']:
            if card not in cards:
                cards[card] = 0
            cards[card] += 1
        hero = hero_map[deck['characterIds'][0]]
        deck = Deck()
        deck.heroes = [hero]
        deck.format = FormatType.FT_STANDARD
        deck.cards = [(reverse_map[x], cards[x]) for x in cards]
        if name not in deck_dict:
            deck_dict[name] = []
        deck_dict[name].append(deck.as_deckstring)
    if code_dest:
        write_to_csv(deck_dict, code_dest)
    else:
        generate_images(deck_dict, dest, ordered)
示例#2
0
import os
import json
from hearthstone.deckstrings import Deck
from hearthstone.enums import FormatType
from hearthstone.cardxml import load
from hearthstone.enums import Locale, Rarity
from collection import Collection

# Create a deck from a deckstring
deck = Deck()
deck.heroes = [7]  # Garrosh Hellscream
deck.format = FormatType.FT_WILD
# Nonsense cards, but the deckstring doesn't validate.
deck.cards = [(1, 3), (2, 3), (3, 3), (4, 3)]  # id, count pairs
print(deck.as_deckstring)  # "AAEBAQcAAAQBAwIDAwMEAw=="

# Import a deck from a deckstring
deck = Deck.from_deckstring(
    "AAEBAf0ECMAB5gT7BPsFigbYE5KsAv2uAgucArsClQONBKsEtAThBJYF7Ae8CImsAgA=")
print(deck.cards)

# load card database from CardDefs.xml and use it to initialize DBF database
db, xml = load(os.path.join("hsdata", "CardDefs.xml"), locale="zhCN")

db_dbf = {}
for card in db:
    #print (card)
    db_dbf[db[card].dbf_id] = db[card]

#print (db)
for cardPair in deck.cards: