基于微博H5 API开发的机器人框架
Project description
WeiboBot 是一个基于微博H5 API开发的机器人框架,提供了一个简单的接口,可以让你的机器人更加简单的接入微博,并且提供了一些简单的指令,比如:转评赞,回复消息等
安装
pip install WeiboBot
开始使用(事件驱动模式)
from WeiboBot import Bot
from WeiboBot.message import Chat
from WeiboBot.weibo import Weibo
from WeiboBot.comment import Comment
from datetime import datetime
cookies = "your cookies"
myBot = Bot(cookies=cookies)
@myBot.onNewMsg # 被私信的时候触发
async def on_msg(chat: Chat):
for msg in chat.msg_list: # 消息列表
print(f"{msg.sender_screen_name}:{msg.text}")
@myBot.onNewWeibo # 首页刷到新微博时触发
async def on_weibo(weibo: Weibo):
if weibo.original_weibo is None: # 是原创微博
print(f"{weibo.text}")
@myBot.onMentionCmt # 提及我的评论时触发
async def on_mention_cmt(cmt: Comment):
print(f"{cmt.text}")
@myBot.onTick # 每次循环触发
async def on_tick():
print(datetime.now())
if __name__ == '__main__':
myBot.run()
开始使用(主动模式)
from WeiboBot import Bot
from WeiboBot.const import *
import asyncio
cookies = "your cookies"
myBot = Bot(cookies=cookies)
async def main():
await asyncio.wait_for(myBot.login(), timeout=10) # 先登录
weibo_example1 = myBot.get_weibo(123456789) # 获取微博
weibo_example2 = myBot.post_weibo("发一条微博", visible=VISIBLE.ALL)
# ...... 其他操作
if __name__ == '__main__':
asyncio.run(main())
如何获取cookie
登录m.weibo.cn
按F12查看请求头
示例
一个转发小姐姐的Bot
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
WeiboBot-0.3.7.tar.gz
(26.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
WeiboBot-0.3.7-py3-none-any.whl
(29.3 kB
view details)
File details
Details for the file WeiboBot-0.3.7.tar.gz.
File metadata
- Download URL: WeiboBot-0.3.7.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2d367ee93d27c172bfcad419544647eea3106ac14ba186c91d12769c715ecaf
|
|
| MD5 |
424e0b838d043797dddcec5baf97e32d
|
|
| BLAKE2b-256 |
d97254042467af8675421a3455adb5753742237cedbd4036b9c97330bf5669c9
|
File details
Details for the file WeiboBot-0.3.7-py3-none-any.whl.
File metadata
- Download URL: WeiboBot-0.3.7-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91be4cd4821d4613123dbba599c18b50fc0f63378fca0ef10c2cfdfe17a7a279
|
|
| MD5 |
6c2ba884e18e3afe85248969ca6853fc
|
|
| BLAKE2b-256 |
d70824e834dcad57d7a65087d9a050628be33e81a19541552f849877ccbeebc1
|