json: Remove "available_markets" field

Otherwise, this makes the file needlessly larger
pull/38/head
Eric Cousineau 2021-05-30 12:45:11 -04:00
parent bf9958c661
commit 8813e83194
1 changed files with 18 additions and 0 deletions

View File

@ -126,6 +126,21 @@ class SpotifyAPI:
self.access_token = access_token
def maybe_delete(d, k):
if k in d:
del d[k]
def scrub_cruft(obj):
if isinstance(obj, dict):
maybe_delete(obj, "available_markets")
for _, v in obj.items():
scrub_cruft(v)
elif isinstance(obj, list):
for v in obj:
scrub_cruft(v)
def main():
# Parse arguments.
parser = argparse.ArgumentParser(description='Exports your Spotify playlists. By default, opens a browser window '
@ -176,6 +191,9 @@ def main():
playlist['tracks'] = spotify.list(playlist['tracks']['href'], {'limit': 100})
playlists += playlist_data
logging.info(f"Scrubbing cruft...")
scrub_cruft(playlists)
# Write the file.
logging.info('Writing files...')
with open(args.file, 'w', encoding='utf-8') as f: