"""Compare schemas.""" import json import pprint import urllib.request pp = pprint.PrettyPrinter(indent=2) REGISTRY_URLS = { 'dev': 'https://dev-schema-registry.dev.theorchard.io', 'qa': 'https://qa-schema-registry.theorchard.io', 'prod': 'https://prod-schema-registry.theorchard.io' } def main(): for environment, url in REGISTRY_URLS.items(): f = urllib.request.urlopen(f'{url}/schemas') raw = f.read().decode('utf-8') parsed = json.loads(raw) parse_res(environment, parsed) def parse_res(environment, res): schemas = {} for schema in res: subject = schema.get('subject') version = f"version_{schema.get('version')}" schema_id = schema.get('id') if subject not in schemas: schemas[subject] = {} schemas[subject][version] = schema_id sorted_schemas = dict(sorted(schemas.items())) print_schemas(environment, sorted_schemas) def print_schemas(environment, schemas): print(environment) for subject, versions in schemas.items(): for version, schema_id in versions.items(): print(f'{subject}:{version}: {schema_id}') if __name__ == '__main__': main()