跳转至

有什么新的内容在icodeapi v1.0.1中?

概述

给tools模块增加了CommentsCleaner方法,用于异步清理评论
改进tools模块的DownloadWork方法,现在它可以下载codeLanguage为"python"的作品,且在识别到不支持的codeLanguage时会抛出TypeError错误
改进tools模块的所有方法,现在临时生成的AsyncIcodeAPI会自动执行closeClient方法
给tools模块的ViewNumMaker方法添加了进度提示
修复了AsyncIcodeAPI.getMyWorks方法参数填入错误的bug
现在IcodeAPI和AsyncIcodeAPI的cookie, info, loginStatus均改为私有成员,添加了同步方法getInfogetLoginStatus让用户获取他们
添加IcodeAPI和AsyncIcodeAPI中login方法的newCookie参数,使一个账号对象可以进行重登录
添加常量DEFAULT_USER_AGENT
优化注释

评论清理者

新的异步函数tools.CommentsCleaner可以让你便捷地清除作品中的评论。

from icodeapi import AsyncIcodeAPI
from icodeapi.tools import CommentsCleaner, ALL_PAGES
import asyncio
async def main():
    api = AsyncIcodeAPI(cookie = input('Enter your cookie'))
    await api.login()
    await CommentsCleaner(
        input('Work ID: '),
         api,
         ALL_PAGES)
    await api.closeClient()
asyncio.run(main())

下载Python作品

tools.DownloadWork函数得到了升级,现在可以下载任意的Python作品,且在识别到不支持的codeLanguage时会抛出TypeError错误。

from icodeapi.tools import DownloadWork
import asyncio
async def main():
    try:
        await DownloadWork(
            input('Work ID: '),
            input('Save Path: '))
    except TypeError:
        pass
    except:
        print('Unknown Error')
asyncio.run(main())

更直观地观察刷浏览器的进度

现在,调用tools.ViewNumMaker方法会打印出部署协程的进度。

获取用户信息和登录状态的新方法

现在IcodeAPI和AsyncIcodeAPI的cookie, info, loginStatus均改为私有成员,添加了同步方法getInfogetLoginStatus让用户获取他们。

from icodeapi import IcodeAPI
cookie = input('Enter your cookie: ')
user = IcodeAPI(cookie)
print(user.getInfo())
print(user.getLoginStatus())

用户对象的重新登录

现在,用户对象可以重新登录一个新的账号,只需要再调用一次IcodeAPI.loginAsyncIcodeAPI.login方法即可。
该功能在TuringAPI就已经被实现,如今终于被重新加入。

from icodeapi import IcodeAPI
cookie = input('Enter your cookie: ')
user = IcodeAPI(cookie)
print(user.getInfo())
cookie = input('Enter your new cookie: ')
user = IcodeAPI(cookie)
print(user.getInfo())