基于微博H5 API开发的机器人框架
Project description
WeiboBot 是一个基于微博H5 API开发的爬虫框架,提供了简单的接口,包括了一些指令,比如:转评赞,回复消息等 可以选择直接获取数据,也可以持续运行
安装
普通安装
pip install WeiboBot
带截图功能
pip install WeiboBot[screenshot]
源码安装(推荐使用uv)
uv sync --all-extras
开始使用(生命周期)
from loguru import logger
from WeiboBot import Bot, ChatDetail, Comment, Weibo
bot = Bot()
@bot.onNewMsg() # 被私信的时候触发
async def on_msg(chat: ChatDetail):
for msg in chat.msgs: # 消息列表
logger.info(f"{msg.sender_screen_name}:{msg.text}")
@bot.onNewWeibo() # 首页刷到新微博时触发
async def on_weibo(weibo: Weibo):
weibo = await bot.weibo_info(weibo.mid) # 获取微博详细信息(长微博才需要)
logger.info(f"{weibo.text}")
@bot.onMentionCmt() # 提及我的评论时触发
async def on_mention_cmt(cmt: Comment):
logger.info(f"收到{cmt.mid}的评论")
@bot.onTick() # 每次循环触发
async def on_tick():
logger.info("tick")
if __name__ == "__main__":
bot.run()
开始使用(仅调用)
import asyncio
from loguru import logger
import WeiboBot.const as const
from WeiboBot import NetTool
async def main():
async with NetTool() as nettool:
user = await nettool.user_info(nettool.mid)
logger.info(user)
weibo_example1 = await nettool.weibo_info(123456) # 获取微博
weibo_example2 = await nettool.post_weibo(
"发一条微博", visible=const.VISIBLE.ONLY_ME
)
# ...... 其他操作
if __name__ == "__main__":
asyncio.run(main())
更新路线图
目前项目仍在重构中
- 对旧API的整合
- 扩展更加多的API
- 提升登录的健壮性
- 增加更多测试用例和自动化
- 去掉 logger
示例
正在重构中
一个转发小姐姐的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-1.2.3.tar.gz
(29.2 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-1.2.3-py3-none-any.whl
(32.7 kB
view details)
File details
Details for the file weibobot-1.2.3.tar.gz.
File metadata
- Download URL: weibobot-1.2.3.tar.gz
- Upload date:
- Size: 29.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b3d158d6eccbed9844d5a4a96a2f9315cf9c56e5c7e64f18d4d32afd2e17432
|
|
| MD5 |
6741be0aaa52e0db1d0040c8c4c68518
|
|
| BLAKE2b-256 |
e1b3912aa4cc62c74db156fab6cff5b4d4506742fdb3e9f4274c025fabb8fdd8
|
File details
Details for the file weibobot-1.2.3-py3-none-any.whl.
File metadata
- Download URL: weibobot-1.2.3-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e70d8e604f6642e7618a5e975f2af2df21fe767118af28d5d0f0229a124dab1
|
|
| MD5 |
9d7b3461c6943877e0039b3d98b4e7e1
|
|
| BLAKE2b-256 |
b4a329a18c362ab290a93fc5db72db364206a6da4d824018c8afed914ca930ed
|