def update_avatar(cookie, tokens, dir_name):
uk = pcs.get_user_uk(cookie, tokens)<EOL>if not uk:<EOL><INDENT>return None<EOL><DEDENT>user_info = pcs.get_user_info(tokens, uk)<EOL>if not user_info:<EOL><INDENT>return None<EOL><DEDENT>img_path = os.path.join(dir_name, '<STR_LIT>')<EOL>if (os.path.exists(img_path) and<EOL>time.time() - os.stat(img_path).st_mtime <= AVATAR_UPDATE_INTERVAL):<EOL><INDENT>return (uk, user_info['<STR_LIT>'], img_path)<EOL><DEDENT>img_url = user_info['<STR_LIT>']<EOL>if not img_url:<EOL><INDENT>return None<EOL><DEDENT>req = net.urlopen(img_url)<EOL>if not req or not req.data:<EOL><INDENT>logger.warn('<STR_LIT>' % url)<EOL>return None<EOL><DEDENT>with open(img_path, '<STR_LIT:wb>') as fh:<EOL><INDENT>fh.write(req.data)<EOL><DEDENT>return (uk, user_info['<STR_LIT>'], img_path)<EOL>
获取用户头像信息