Advertisement
Guest User

Untitled

a guest
Jan 29th, 2021
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. from collections import defaultdict
  2. response = [
  3.     {'Alliances': [{'Near Mint': '$119.99'}]},
  4.     {'Double Masters': [{'Near Mint': '$109.99'}]},
  5.     {'Double Masters (Foil)': [{'Near Mint': '$199.99'}]},
  6.     {'Double Masters - Variants': [{'Near Mint': '$199.99'}]},
  7.     {'Double Masters - Variants (Foil)': [{'Near Mint': '$329.99'}]},
  8.     {'Eternal Masters': [{'Near Mint': '$109.99'}]},
  9.     {'Eternal Masters (Foil)': [{'Near Mint': '$399.99'}]},
  10.     {'Masterpiece Series: Amonkhet Invocations (Foil)': [{'Near Mint': '$249.99'}]},
  11.     {'Promo: General (Foil)': [{'Near Mint': '$499.99'}]},
  12. ]
  13.  
  14. def prepare_data(govno):
  15.     intermediate = {k: v for d in govno for k, v in d.items()}
  16.     formatted = defaultdict(lambda: {})
  17.     for name, cards in intermediate.items():
  18.         for suffix in [' - Variants (Foil)', ' - Variants', ' (Foil)']:
  19.             if name.endswith(suffix):
  20.                 name = name.replace(suffix, '')
  21.                 suffix = 'Foil' if suffix == ' (Foil)' else suffix.strip(' -')
  22.             else:
  23.                 suffix = 'C'
  24.             formatted[name][suffix] = cards
  25.     return formatted
  26.  
  27. def prepare_cards(cards):
  28.     res = [f'{state}: {price}' for card in cards for state, price in card.items()]
  29.     return res
  30.  
  31. def prepare_output(prepared):
  32.     lines = []
  33.     for set_name, variants in prepared.items():
  34.         lines.append(f'{set_name}')
  35.         for variant, cards in sorted(variants.items()):
  36.             if variant != 'C':
  37.                 lines.append(f'{variant}:')
  38.             lines += prepare_cards(cards)
  39.     return lines
  40.  
  41. print('\n'.join(prepare_output(prepare_data(response))))
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement