Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. from mtgsdk import Set
  2. from mtgsdk import Card
  3. from mtgsdk import Supertype
  4.  
  5. def main():
  6.     # change parameters to refine serach - leave '' to filter by all
  7.     name = ''
  8.     colors = 'Green' # pipe is or
  9.     card_type = 'Creature' # enchantment, sorcery, creature, etc.
  10.     super_types = ''
  11.     sub_types = 'Worm'
  12.     #cmc = '1.0,2.0,3.0'
  13.     text = '' # contains this keyword?
  14.  
  15.     # if you want to output query to a file - change file name when you run a new query
  16.     file_path = 'G:\Documents\MTG\API Queries\_testRedCreatures.txt'
  17.  
  18.     # query for the
  19.     cards = Card.where(name=name).where(colors=colors).where(type=card_type).where(superTypes=super_types).where(subtypes=sub_types).all()
  20.  
  21.     results = 1
  22.  
  23.     # write the parameters used at the top of the file
  24.     # edit when you run a new query
  25.     # JANKY AF BUT I CAN'T THINK OF ANOTHER WAY
  26.     with open(file_path, "a") as myfile:
  27.         myfile.write("-----Parameters used-----")
  28.         myfile.write("\n")
  29.  
  30.         myfile.write("name: ")
  31.         myfile.write(name)
  32.         myfile.write("\n")
  33.  
  34.         myfile.write("colors: ")
  35.         myfile.write(colors)
  36.         myfile.write("\n")
  37.  
  38.         myfile.write("card_type: ")
  39.         myfile.write(card_type)
  40.         myfile.write("\n")
  41.  
  42.         myfile.write("super_types: ")
  43.         myfile.write(super_types)
  44.         myfile.write("\n")
  45.  
  46.         myfile.write("sub_types: ")
  47.         myfile.write(sub_types)
  48.         myfile.write("\n")
  49.  
  50.         myfile.write("-----End Parameters-----")
  51.         myfile.write("\n")
  52.         myfile.write("\n")
  53.  
  54.     # loop through the cards and print out details
  55.     for card in cards:
  56.         print("Result #: ", results)
  57.         card_info = ("Name: {}\n"
  58.                      "Layout: {}\n"
  59.                      "Converted Mana Cost: {}\n"
  60.                      "Colors: {}\n"
  61.                      "Types: {}\n"
  62.                      "SuperType: {}\n"
  63.                      "SubType: {}\n"
  64.                      "Rarity: {}\n"
  65.                      "Power: {}\n"
  66.                      "Toughness: {}\n"
  67.                      "Card Text: {}\n"
  68.                      ).format(card.name,
  69.                               card.layout,
  70.                               card.cmc,
  71.                               card.colors,
  72.                               card.type,
  73.                               card.supertypes,
  74.                               card.subtypes,
  75.                               card.rarity,
  76.                               card.power,
  77.                               card.toughness,
  78.                               card.text)
  79.         print(card_info, "\n")
  80.  
  81.         # write query results out to a txt file
  82.         with open(file_path, "a") as myfile:
  83.             myfile.write("Result #: ")
  84.             myfile.write(str(results)) # cast int as string
  85.             myfile.write("\n")
  86.             myfile.write(card_info)
  87.             myfile.write("\n")
  88.  
  89.         results = results + 1
  90.     myfile.close()
  91. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement