parameters: (strategy, details, response, user, *args, **kwargs)
docstring: Try to get user profile avatar from social networks.
docstring_summary: Try to get user profile avatar from social networks.
docstring_tokens: Try to get user profile avatar from social networks .
function: def get_user_avatar(strategy, details, response, user, *args, **kwargs):
      """ Try to get user profile avatar from social networks.
      """
      image_url = None
      is_default = True
      TMP_FILE = os.path.join(settings.BASE_DIR, 'media/tmp/image')
  
      # Get image info from social sites
      if kwargs['backend'].name == 'twitter':
          image_url = response.get('profile_image_url_https').replace('_normal', '')
          is_default = response.get('default_profile_image')
  
      elif kwargs['backend'].name == 'facebook':
          base_url = 'https://graph.facebook.com/{}/picture?{}'
          data = json.loads(urllib.urlopen(base_url.format(response.get('id'),
                                                      'redirect=false')).read())
          if not data.get('is_silhouette'):
              image_url = base_url.format(response.get('id'), 'type=large')
              is_default = False
  
      elif kwargs['backend'].name == 'google-plus':
          is_default = response.get('image')['isDefault']
          if not is_default:
              image_url = response.get('image')['url'].replace('sz=50', 'sz=200')
  
      # Download image and replace profile avatar
      if image_url is not None and not is_default and user.profile.has_default_avatar:
          urllib.urlretrieve(image_url, TMP_FILE)
          image = Image.open(TMP_FILE)
          try:
              update_profile_picture(user.profile, image)
          except Exception:
              pass
function_tokens: def get_user_avatar ( strategy , details , response , user , * args , * * kwargs ) : image_url = None is_default = True TMP_FILE = os . path . join ( settings . BASE_DIR , 'media/tmp/image' ) # Get image info from social sites if kwargs [ 'backend' ] . name == 'twitter' : image_url = response . get ( 'profile_image_url_https' ) . replace ( '_normal' , '' ) is_default = response . get ( 'default_profile_image' ) elif kwargs [ 'backend' ] . name == 'facebook' : base_url = 'https://graph.facebook.com/{}/picture?{}' data = json . loads ( urllib . urlopen ( base_url . format ( response . get ( 'id' ) , 'redirect=false' ) ) . read ( ) ) if not data . get ( 'is_silhouette' ) : image_url = base_url . format ( response . get ( 'id' ) , 'type=large' ) is_default = False elif kwargs [ 'backend' ] . name == 'google-plus' : is_default = response . get ( 'image' ) [ 'isDefault' ] if not is_default : image_url = response . get ( 'image' ) [ 'url' ] . replace ( 'sz=50' , 'sz=200' ) # Download image and replace profile avatar if image_url is not None and not is_default and user . profile . has_default_avatar : urllib . urlretrieve ( image_url , TMP_FILE ) image = Image . open ( TMP_FILE ) try : update_profile_picture ( user . profile , image ) except Exception : pass