Last active
May 27, 2019 16:32
-
-
Save juanitobanca/986d6748a99bc4beccc53cb1a43b58d1 to your computer and use it in GitHub Desktop.
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
import requests | |
def obtenerEstructura( diccionario, estructura ): | |
for llave in diccionario: | |
if isinstance( diccionario[llave], dict ): | |
estructura[llave] = obtenerEstructura( diccionario[llave], {} ) | |
else: | |
estructura[llave] = type( diccionario[llave] ).__name__ | |
return estructura | |
def imprimirEstructura( estructura, numEspacios ): | |
espacios = ' '*( 4*numEspacios ) | |
for llave in estructura: | |
if isinstance( estructura[llave], dict ): | |
print( espacios+llave+':') | |
print( espacios+'{' ) | |
imprimirEstructura( estructura[llave], numEspacios + 1 ) | |
print( espacios+'}' ) | |
else: | |
print( espacios+llave+' : '+estructura[llave] ) | |
miTexto = requests.get('http://statsapi.mlb.com/api/v1/game/431674/contextMetrics') | |
miJson = miTexto.json() | |
estructura = obtenerEstructura( miJson, {} ) | |
print( '{' ) | |
imprimirEstructura( estructura, 1 ) | |
print( '}' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment