def parse_deck(self, response): # if tavern brawl deck, don't add it deckType = response.css('span.deck-type::text').get() self.connectToDatabase() data = {} data['deck'] = [] for deckcode in response.css('html'): code = deckcode.css('button::attr(data-clipboard-text)').get() link = response.css('link::attr(href)')[1].get() fullDeck = deckstrings.parse_deckstring(code) print(fullDeck) # query = "INSERT INTO test1(deckcode,url) " \ # "VALUES(%s,%s)" # args = (code, link) # cursor = self.conn.cursor() # result = cursor.execute(query, args) # self.conn.commit() # last_ID = "SELECT deck_id FROM test1 ORDER BY deck_id DESC LIMIT 1" # assumes there is at least 1 row in the table #get last ID and add 1 to it for i in range(len(fullDeck[0])): card = fullDeck[0][i][ 0] #cycles through the first array in the list, pulling the first item which is the card number print(card)
def decode_deckstring(s, to="List"): deckTuple = deckstrings.parse_deckstring(s)[0] if to == "string": deckList = "[" for each in deckTuple: #print(each) #(cardID, number of cards in the deck) for i in range(each[1]): cardName = getCardnameFromDbf(each[0]) result1 = cardName.translate( str.maketrans('', '', string.punctuation)) result2 = result1.replace(' ', '') deckList += result2 + ', ' deckList += ']' return deckList else: #to == "List" deckList = [] for each in deckTuple: #print(each) #(cardID, number of cards in the deck) for i in range(each[1]): cardName = getCardnameFromDbf(each[0]) result1 = cardName.translate( str.maketrans('', '', string.punctuation)) result2 = result1.replace(' ', '') className = typeName2Class(result2) deckList.append(className) return deckList
def _classify_deck(self, format_type, player_class, deckstring): if not deckstring: return None cards, _, _ = parse_deckstring(deckstring) if (sum([c[1] for c in cards])) != 30: return None signature_weights = ClusterSnapshot.objects.get_signature_weights( format_type, player_class) dbf_map = {card[0]: card[1] for card in cards} return classify_deck(dbf_map, signature_weights)
def __init__(self, deckstring = ""): self._cards = [] if deckstring: cards = parse_deckstring(deckstring) self._hero = Cards().getById(cards[1][0]) self._type = cards[2] for card in cards[0]: self._cards.append(Cards().getById(card[0])) if(card[1] == 2): self._cards.append(Cards().getById(card[0]))
def verify_archetype_classification(archetype_id, vod, signature_weights): if not is_valid_vod(vod): return False deckstring = vod.friendly_player_canonical_deck_string if not deckstring: return False cards, _, _ = parse_deckstring(deckstring) if (sum([c[1] for c in cards])) != 30: return False dbf_map = {card[0]: card[1] for card in cards} new_archetype_id = classify_deck(dbf_map, signature_weights) return new_archetype_id == archetype_id
def _create_deck(deckstring, archetype_id=None): cards, heroes, format = parse_deckstring(deckstring) card_ids = [] for card in cards: for _ in range(card[1]): card_ids.append(Card.objects.get(dbf_id=card[0]).id) deck_list, _ = Deck.objects.get_or_create_from_id_list( card_ids, hero_id=heroes[0], game_type=BnetGameType.BGT_RANKED_STANDARD) if archetype_id: archetype = Archetype(id=archetype_id) archetype.save() deck_list.archetype = archetype deck_list.save() return deck_list
def _get_deck_from_deckstring(deckstring): cardlist, _, _ = parse_deckstring(deckstring) return {dbf_id: count for (dbf_id, count) in cardlist}