Advertisement
desdemona

hs

May 29th, 2017
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. import re
  2. from CardCollection import CardCollection
  3.  
  4. deck_filename = "deck.txt"
  5.  
  6.  
  7.  
  8. def main():
  9.     number_of_cards = 0
  10.  
  11.     random_counter = 0
  12.     taunt_counter = 0
  13.     deal_counter = 0
  14.     give_counter = 0
  15.     discover_counter = 0
  16.  
  17.     card_collection = CardCollection()
  18.  
  19.     text_key = "text"
  20.  
  21.     for line in open(deck_filename, encoding="utf8"):
  22.         card_name = line.strip().lower()
  23.         print("Card name: " + card_name)
  24.  
  25.         card = card_collection.get_card_by_name(card_name)
  26.         if card is None:
  27.             print("Error: Card not found")
  28.             continue
  29.  
  30.         if text_key not in card:
  31.             print("Card has no text")
  32.         else:
  33.             card_text = str(card[text_key]).strip().lower()
  34.             random_counter += count_random(card_text)
  35.             taunt_counter += count_taunt(card_text)
  36.             deal_counter += count_deal(card_text)
  37.             give_counter += count_give(card_text)
  38.             discover_counter += count_discover(card_text)
  39.  
  40.         number_of_cards += 1
  41.         print(str(card))
  42.  
  43.     print()
  44.     print("Deck parsed, " + str(number_of_cards) + " cards.")
  45.     if number_of_cards is not 30:
  46.         print("Wrong number of cards")
  47.         return
  48.  
  49.     if random_counter != taunt_counter != deal_counter != give_counter != discover_counter != 5:
  50.         print("deck is fucked")
  51.         return
  52.  
  53.  
  54. def count_random(text):
  55.     keywords = ["random", "randomly"]
  56.     return count_words_in_text(text, keywords)
  57.  
  58.  
  59. def count_deal(text):
  60.     keywords = ["deal", "deals"]
  61.     return count_words_in_text(text, keywords)
  62.  
  63.  
  64. def count_taunt(text):
  65.     keywords = ["taunts", "taunt"]
  66.     return count_words_in_text(text, keywords)
  67.  
  68.  
  69. def count_give(text):
  70.     keywords = ["give", "gives"]
  71.     return count_words_in_text(text, keywords)
  72.  
  73.  
  74. def count_discover(text):
  75.     keywords = ["discover", "discovers"]
  76.     return count_words_in_text(text, keywords)
  77.  
  78.  
  79. def count_words_in_text(text, list_of_words):
  80.     count = 0
  81.     word_list = re.split(r'\W', text)
  82.     for word in list_of_words:
  83.         count += word_list.count(word)
  84.  
  85.     return count
  86.  
  87. if __name__ == "__main__":
  88.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement