Created
August 3, 2016 00:18
-
-
Save solidpple/fd7e1f4bcf014b4559da8d0616681a5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import json, os | |
| import Proto import Tweet_pb2 as LogDataProto | |
| import protobuf_to_dict import protobuf_to_dict | |
| filename="tweet.log" # proto type | |
| # read protobuf file | |
| f = open(filename, "r") | |
| try: | |
| logfile = LogDataProto.LogDataFile() | |
| logfile.ParseFromString(f.read()) | |
| except (IndexError, TypeError): | |
| print 'index, type error' | |
| # protobuf to json | |
| logfile_dict = protobuf_to_dict(logfile) | |
| json_string = json.dumps(logfile_dict, encoding='utf-8') | |
| # write json file | |
| new_filename = os.path.splitext(filename)[0] + '.json' | |
| f = open(new_filename, 'w') | |
| f.write(json_string.encode("utf-8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment