Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- from CardCollection import CardCollection
- deck_filename = "deck.txt"
- def main():
- number_of_cards = 0
- random_counter = 0
- taunt_counter = 0
- deal_counter = 0
- give_counter = 0
- discover_counter = 0
- card_collection = CardCollection()
- text_key = "text"
- for line in open(deck_filename, encoding="utf8"):
- card_name = line.strip().lower()
- print("Card name: " + card_name)
- card = card_collection.get_card_by_name(card_name)
- if card is None:
- print("Error: Card not found")
- continue
- if text_key not in card:
- print("Card has no text")
- else:
- card_text = str(card[text_key]).strip().lower()
- random_counter += count_random(card_text)
- taunt_counter += count_taunt(card_text)
- deal_counter += count_deal(card_text)
- give_counter += count_give(card_text)
- discover_counter += count_discover(card_text)
- number_of_cards += 1
- print(str(card))
- print()
- print("Deck parsed, " + str(number_of_cards) + " cards.")
- if number_of_cards is not 30:
- print("Wrong number of cards")
- return
- if random_counter != taunt_counter != deal_counter != give_counter != discover_counter != 5:
- print("deck is fucked")
- return
- def count_random(text):
- keywords = ["random", "randomly"]
- return count_words_in_text(text, keywords)
- def count_deal(text):
- keywords = ["deal", "deals"]
- return count_words_in_text(text, keywords)
- def count_taunt(text):
- keywords = ["taunts", "taunt"]
- return count_words_in_text(text, keywords)
- def count_give(text):
- keywords = ["give", "gives"]
- return count_words_in_text(text, keywords)
- def count_discover(text):
- keywords = ["discover", "discovers"]
- return count_words_in_text(text, keywords)
- def count_words_in_text(text, list_of_words):
- count = 0
- word_list = re.split(r'\W', text)
- for word in list_of_words:
- count += word_list.count(word)
- return count
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement