Created
May 16, 2016 14:46
-
-
Save ivanrvpereira/7bc2b546ddc468ac26819cb0a011c78f to your computer and use it in GitHub Desktop.
Converts base64 application/x-python-serialize in rabbitmq to human readable json for easier debug
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 click | |
import base64 | |
import pickle | |
import pprint | |
@click.command() | |
@click.argument('b64body') | |
@click.option('--indent', default=2, type=int) | |
def unserialize(b64body, indent): | |
m = "".join(b64body.strip().split("\n")) | |
try: | |
res = pickle.loads(base64.b64decode(m)) | |
pp = pprint.PrettyPrinter(indent=indent) | |
click.echo("") | |
pp.pprint(res) | |
except TypeError: | |
click.echo("Cannot parse this base64 body") |
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
from setuptools import setup | |
setup( | |
name='b64tojson', | |
version='0.1', | |
py_modules=['b64tojson'], | |
install_requires=[ | |
'Click', | |
], | |
entry_points=''' | |
[console_scripts] | |
b64tojson=b64tojson:unserialize | |
''', | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download both files to a directory and then inside the directory
$ pip install .