#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2016-2017 Anaconda, Inc.
#
# May be copied and distributed freely only as part of an Anaconda or
# Miniconda installation.
# -----------------------------------------------------------------------------
"""Helper utility to clean up json bundled content."""

# Standard library imports
import json
import sys


def verify(content):
    """Verify the content keys."""
    for item in content:
        for key in "tags title summary banner uri image_file_path".split():
            if key not in item:
                name = item.get("title")
                if name is None:
                    name = item.get("uri")
                if name is None:
                    name = "UNKNOWN"
                print(name, "is missing key", key)


if __name__ == '__main__':
    for fname in sys.argv[1:]:
        with open(fname) as f:
            content = json.load(f)
        if 'links.json' in fname:
            verify(content)
        with open(fname, 'w') as out:
            out.write(json.dumps(content, indent=2))
