(url)
保存用户头像
    :param url:头像url
    :return: 本地路径
保存用户头像
    :param url:头像url
    :return: 本地路径
保存用户头像 : param url : 头像url : return : 本地路径
def save_user_avatar(url):
    '''
    保存用户头像
    :param url:头像url
    :return: 本地路径
    '''
    setting = get_blog_setting()
    logger.info(url)

    try:
        imgname = url.split('/')[-1]
        if imgname:
            path = r'{basedir}/avatar/{img}'.format(
                basedir=setting.resource_path, img=imgname)
            if os.path.exists(path):
                os.remove(path)
        rsp = requests.get(url, timeout=2)
        if rsp.status_code == 200:
            basepath = r'{basedir}/avatar/'.format(
                basedir=setting.resource_path)
            if not os.path.exists(basepath):
                os.makedirs(basepath)

            imgextensions = ['.jpg', '.png', 'jpeg', '.gif']
            isimage = len([i for i in imgextensions if url.endswith(i)]) > 0
            ext = os.path.splitext(url)[1] if isimage else '.jpg'
            savefilename = str(uuid.uuid4().hex) + ext
            logger.info('保存用户头像:' + basepath + savefilename)
            with open(basepath + savefilename, 'wb+') as file:
                file.write(rsp.content)
            return 'https://resource.lylinux.net/avatar/' + savefilename
    except Exception as e:
        logger.error(e)
        return url
def save_user_avatar ( url ) : setting = get_blog_setting ( ) logger . info ( url ) try : imgname = url . split ( '/' ) [ - 1 ] if imgname : path = r'{basedir}/avatar/{img}' . format ( basedir = setting . resource_path , img = imgname ) if os . path . exists ( path ) : os . remove ( path ) rsp = requests . get ( url , timeout = 2 ) if rsp . status_code == 200 : basepath = r'{basedir}/avatar/' . format ( basedir = setting . resource_path ) if not os . path . exists ( basepath ) : os . makedirs ( basepath ) imgextensions = [ '.jpg' , '.png' , 'jpeg' , '.gif' ] isimage = len ( [ i for i in imgextensions if url . endswith ( i ) ] ) > 0 ext = os . path . splitext ( url ) [ 1 ] if isimage else '.jpg' savefilename = str ( uuid . uuid4 ( ) . hex ) + ext logger . info ( '保存用户头像:' + basepath  avefilen m ) with open ( basepath + savefilename , 'wb+' ) as file : file . write ( rsp . content ) return 'https://resource.lylinux.net/avatar/' + savefilename except Exception as e : logger . error ( e ) return url