Created
October 23, 2018 13:16
-
-
Save eirenik0/5c3dcc2651488c7d4f0d0f3d0e065306 to your computer and use it in GitHub Desktop.
Get sorted Json from URL where object is zipped Json string
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 requests | |
import io | |
import gzip | |
import pyperclip | |
import json | |
def get_sorted_json(url): | |
buff = io.BytesIO() | |
r = requests.get(url, stream=True) | |
for chunk in r.iter_content(chunk_size=1024): | |
if chunk: | |
buff.write(chunk) | |
buff.seek(0) | |
json_obj = json.loads(gzip.GzipFile(fileobj=buff, mode='rb').read()) | |
return json.dumps(json_obj, sort_keys=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment