Giter VIP home page Giter VIP logo

weibobot's Introduction

WeiboBot

基于微博H5 API开发的机器人框架

PyPI Python Version Python Implementation

License

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查看请求头

image

示例

好康Bot

一个转发小姐姐的Bot

weibobot's People

Contributors

merlincn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.