Created
May 10, 2012 14:43
-
-
Save kojiromike/2653592 to your computer and use it in GitHub Desktop.
Completely untested avro pretty-printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Translate avro into json and pretty print it. | |
from avro import schema | |
from avro.io import BinaryDecoder, DatumReader | |
from json import dumps | |
from sys import argv | |
def read_avro(avro_file_no_schema, avro_schema): | |
"""Translate avro into python data objects and return that.""" | |
with open(avro_file_no_schema, 'r') as body_file: | |
decoder = BinaryDecoder(body_file) | |
reader = DatumReader(avro_schema) | |
return reader.read(decoder) | |
if '__main__' == __name__: | |
avro_file_no_schema = argv[1] | |
avro_schema_file = argv[2] | |
with open(avro_schema_file, 'r') as schema_file: | |
data = read_avro(avro_file_no_schema, schema.parse(schema_file)) | |
print dumps(data, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment