Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- response = [
- {'Alliances': [{'Near Mint': '$119.99'}]},
- {'Double Masters': [{'Near Mint': '$109.99'}]},
- {'Double Masters (Foil)': [{'Near Mint': '$199.99'}]},
- {'Double Masters - Variants': [{'Near Mint': '$199.99'}]},
- {'Double Masters - Variants (Foil)': [{'Near Mint': '$329.99'}]},
- {'Eternal Masters': [{'Near Mint': '$109.99'}]},
- {'Eternal Masters (Foil)': [{'Near Mint': '$399.99'}]},
- {'Masterpiece Series: Amonkhet Invocations (Foil)': [{'Near Mint': '$249.99'}]},
- {'Promo: General (Foil)': [{'Near Mint': '$499.99'}]},
- ]
- def prepare_data(govno):
- intermediate = {k: v for d in govno for k, v in d.items()}
- formatted = defaultdict(lambda: {})
- for name, cards in intermediate.items():
- for suffix in [' - Variants (Foil)', ' - Variants', ' (Foil)']:
- if name.endswith(suffix):
- name = name.replace(suffix, '')
- suffix = 'Foil' if suffix == ' (Foil)' else suffix.strip(' -')
- else:
- suffix = 'C'
- formatted[name][suffix] = cards
- return formatted
- def prepare_cards(cards):
- res = [f'{state}: {price}' for card in cards for state, price in card.items()]
- return res
- def prepare_output(prepared):
- lines = []
- for set_name, variants in prepared.items():
- lines.append(f'{set_name}')
- for variant, cards in sorted(variants.items()):
- if variant != 'C':
- lines.append(f'{variant}:')
- lines += prepare_cards(cards)
- return lines
- print('\n'.join(prepare_output(prepare_data(response))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement