做些什么
进行一些操作
这些操作均需要登录,如果IcodeAPI
或AsyncIcodeAPI
对象没有登录,执行这些操作将抛出LoginError
异常。
对作品操作
进行评论
使用IcodeAPI.comment
方法。
workId : 作品id
content : 评论内容
注意,评论操作有5秒的时间限制。
对一个作品进行点赞
使用IcodeAPI.like
方法。
workId : 作品id
mode : 1为点赞,2为取消点赞
注意,点赞操作有3秒的时间限制。
对一个作品进行收藏
使用IcodeAPI.enshrine
方法。
workId : 作品id
mode : 1为收藏,2为取消收藏
发布一个作品
使用IcodeAPI.submitWork
。
def submitWork(self, workCode : str = '',
workType : str = 'Scratch',
publish : int = 1,
save : int = False,
title : str = 'Scratch Project',
description : str = 'Project Description',
thumbnail : str = 'http://ydschool-online.nosdn.127.net/svg/0c3a986d5266bd5a186014aebd219e05c9696de777dea2b5dfe658dc661e572c.png',
fork : int = 0,
workDetail : tuple = None,
workId : str = None) -> dict
workCode : 作品代码,Scratch作品需要传入json数据
workType : 作品类型,'Scratch'为Scratch,'Python'为Python,开头字符不区分大小写
publish : 发布状态,1为发布,2为不发布
save : 保存状态
title : 作品标题
description : 作品描述
thumbnail : 作品封面url
fork : 作品是否允许改编,0为不允许,1为允许
workDetail : 传入这个参数可以自动读取数据并发布作品,要求一个元组,第一个元素是IcodeAPI.getWorkDetail
的返回值,第二个元素是IcodeAPI.getWorkSubmitInfo
的返回值
workId : 如果传入这个参数将会重新发布作品id为这个参数的作品
原英文注释:
'''
Submit a work.
This function only supported to submit Scratch or Python work, no Blockly.
If the workId isnt None, the function will reSubmit the work.
When the workType is Python, and the save is true, the funciton will only save the work, not publish the work.
If publish = 1, the function will publish the work, when it is 2, the fucntion will unpublish the work.
If fork = 1, allow others to fork your work, if fork = 0, dont allow others to fork your work.
If workDetail should be a tuple. workDetail[0] = `getWorkDetail()` return value, workDetail[1] = `getWorkSubmitInfo()` return value.
'''
这个方法可以发布scratch或Python作品,但不支持发布Blockly作品。如果workId不为None,则重新发布workId为workId的作品。当workType为Python,且save为True时,函数只会保存作品,而不会发布作品。当publish = 1时,函数会发布作品,当publish = 2时,函数不会发布作品。当fork = 1时,允许其他人 fork 你的作品,当fork = 0时,不允许其他人 fork 你的作品。当workDetail为元组时,必须有以下格式:workDetail[0] =
getWorkDetail()
返回值,workDetail[1] = getWorkSubmitInfo()
返回值,方法内部会自动读取数据并发布作品。示例:
from icodeapi import IcodeAPI
COOKIE = input('Enter cookie: ')
user = IcodeAPI(cookie = COOKIE)
info = user.submitWork('print("Hello IcodeAPI")',
'python',
save = True,
title = 'Hello IcodeAPI',
description = 'save by icodeapi'
)
print(info)
workId = info.get('data')
info = user.submitWork(workDetail = (user.getWorkDetail(workId), user.getWorkSubmitInfo(workId)))
print(info)
{
'code': 0,
'msg': 'success',
'data': '0',
'user': {
'userId': 'qqCD6566A4CF1F39111AE5246D138220CA',
'name': 'qqcd',
'image': 'https://oimageb6.ydstatic.com/image?id=6039990957530368796&product=xue&format=PNG'
}
}
{
'code': 0,
'msg': 'success',
'data': '70e527af8b5949049bf0ebf0da0b5998',
'user': {
'userId': 'qqCD6566A4CF1F39111AE5246D138220CA',
'name': 'qqcd',
'image': 'https://oimageb6.ydstatic.com/image?id=6039990957530368796&product=xue&format=PNG'
}
}
删除一个作品
使用IcodeAPI.deleteWork
方法。
workId : 需要删除的作品id
社交性操作
进行举报
使用IcodeAPI.report
方法。
def report(self,
reportType : Work | Reply | Comment | User,
reason : str,
reportCategory : int,
reportId : str,
copyWorksUrl : str | None = None) -> dict
reportType : 举报类型,可以为Work,Reply,Comment和User类(非对象)
reason : 举报原因
reportCategory : 举报类型,1:抄袭,2:商业广告,3:人身攻击,4:违法违规,5:未成年人不宜(当举报类型不是作品时,只有后四项,并且编号补全前面的抄袭,也就是1、2、3、4)
reportId : 举报对象的id,此参数需要随举报类型而变,例如举报类型为Comment时需要填入commentId
copyWorksUrl : 抄袭作品链接,当举报类型为Work且reportCategory为1时需要填写
对个人简介进行修改
使用IcodeAPI.updateIntro
方法。
intro : 新的简介,默认为'IcodeAPI...'
回复一条评论
使用IcodeAPI.reply
方法。
content : 回复内容
commentId : 要回复的评论id
replyId : 要回复的回复id,默认为None
该方法可以给一个评论回复,也可以给一个评论的回复回复。
删除一条评论
使用IcodeAPI.deleteComment
方法。
commentId : 要删除的评论id,默认为None
replyId : 要删除的回复id,默认为None
这个方法可以删除一条评论或一条回复。
获取一条评论包含的回复
使用IcodeAPI.getReplies
方法。
commentId : 要获取回复的评论id
page : 获取回复的页数,默认为1
getNum : 获取的回复数量,默认为20
当获取的是一个评论的所有回复时,返回值通常有如下格式:
[ # When this reply is a reply to a comment
{
"id": str, # 回复的id
"content": str, # 回复的内容
"type": int, # 回复的类型
"commentId": int, # 回复的评论id
"userId": str, # 发布者的userId
"name": str, # 发布者的昵称
"image": str, # 发布者的头像
"isAuthor": bool, # 是否为作者发布的回复
"time": int, # 回复的时间
"praiseNum": int, # 点赞数
"hasPraised": bool # 当前账号是否点赞了
}
]
[ # When this reply is a reply to an another reply
{
"id": int, # 回复的id
"content": str, # 回复的内容
"type": int, # 回复的类型
"commentId": str, # 回复的评论id
"userId": str, # 发布者的userId
"name": str, # 发布者的昵称
"image": str, # 发布者的头像
"isAuthor": bool, # 是否为作者发布的回复
"replyUserId": str, # 回复的发布者userId
"replyName": str, # 回复的发布者昵称
"replyImage": str, # 回复的发布者头像
"time": int, # 回复的时间
"praiseNum": int, # 点赞数
"hasPraised": bool # 当前账号是否点赞了
}
]
获取用户消息中心里推送的消息
使用IcodeAPI.getMessages
方法。
messageType : 获取的消息类型,默认为回复消息,可选的有
reply
、enshrine
、system
page : 获取消息的页数,默认为1
getNum : 获取的消息数量,默认为20
返回值通常有以下格式:
[
{
'actionUserId': str, # 消息发出者的userId
'actionUserImage': str, # 消息发布者的图片
'actionUserName': str, # 消息发布者的昵称
'createTime': str, # 消息发布时间
'createTimeStr': str, # 消息发布时间
'haveRead': bool, # 是否已读
'id': int, # 消息的id
'content' : str, # 消息的内容
'type': int, # 消息的类型
'worksId': str, # 消息所属的作品的id
'worksTitle': str # 消息所属的作品的标题
}
]
获取当前未读消息数量
使用IcodeAPI.countMessages
方法。
{
'count' : int, # message number
'messageList' : [
{
'id' : int, # message id
'worksTitle' : str,
"actionUserId": str,
"actionUserName": str,
"actionUserImage": str,
"type": int,
"haveRead": bool,
"createTimeStr": str
}
]
}
删除一条消息
使用IcodeAPI.deleteMessage
方法。
messageId : 要删除的消息的ID
对一条评论或者一条回复点赞
使用IcodeAPI.praiseComment
方法。
commentId : 评论的ID
replyId : 回复的ID
mode : 点赞的模式,默认为1即点赞,当为2时取消点赞
将一条消息设为已读
使用IcodeAPI.readMessage
方法。
messageId : 要设为已读的消息的ID
将所有消息设为已读
使用IcodeAPI.readAllMessages
方法。
tab : 消息的类型,默认为1即所有评论消息,当为2时所有收藏消息,当3为所有系统消息
文件床操作
上传一个文件到小图灵文件床
使用IcodeAPI.uploadFile
方法。
name : 文件名
suffix : 文件后缀名
file : 文件内容
注意,小图灵文件床只支持Scratch支持上传的asset文件类型,如mp3, svg等。
示例: