Weibo微博自动发帖机器人,新浪微博自动发帖脚本,微博自动发布工具分享

简介: 这个微博机器人系统包含完整的OAuth2.0认证流程、定时任务调度、多种内容类型发布和自动回复功能

下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:7718

这个微博机器人系统包含完整的OAuth2.0认证流程、定时任务调度、多种内容类型发布和自动回复功能。使用时需要先在新浪微博开放平台申请应用获取API Key,配置好config.json文件后即可运行。

!/usr/bin/env python3

-- coding: utf-8 --

import json
import time
import random
import schedule
from datetime import datetime
from weibo_api import WeiboAPI
from content_manager import ContentManager

class WeiboBot:
def init(self, config_file='config.json'):
with open(config_file) as f:
self.config = json.load(f)
self.api = WeiboAPI(
app_key=self.config['app_key'],
app_secret=self.config['app_secret'],
callback_url=self.config['callback_url']
)
self.content_mgr = ContentManager()
self._setup_schedule()

def _setup_schedule(self):
    # 定时任务配置
    schedule.every().day.at("09:00").do(self.post_random_content)
    schedule.every().day.at("12:00").do(self.post_random_content)
    schedule.every().day.at("18:00").do(self.post_random_content)
    schedule.every(3).hours.do(self.check_messages)

def post_random_content(self):
    content_type = random.choice(['text', 'image', 'video'])
    if content_type == 'text':
        text = self.content_mgr.get_random_text()
        self.api.post_text(text)
    elif content_type == 'image':
        text = self.content_mgr.get_random_text()
        image_path = self.content_mgr.get_random_image()
        self.api.post_image(text, image_path)
    else:
        text = self.content_mgr.get_random_text()
        video_path = self.content_mgr.get_random_video()
        self.api.post_video(text, video_path)
    print(f"[{datetime.now()}] Posted {content_type} content")

def check_messages(self):
    messages = self.api.get_unread_messages()
    for msg in messages:
        if msg['type'] == 'comment':
            self._handle_comment(msg)
    print(f"[{datetime.now()}] Checked {len(messages)} messages")

def _handle_comment(self, comment):
    # 自动回复逻辑
    reply = self.content_mgr.get_comment_reply(comment['content'])
    self.api.reply_comment(comment['id'], reply)

def run(self):
    print("Weibo Bot started...")
    while True:
        schedule.run_pending()
        time.sleep(60)

if name == 'main':
bot = WeiboBot()
bot.run()

requests
import base64
from urllib.parse import quote

class WeiboAPI:
def init(self, app_key, app_secret, callback_url):
self.base_url = "https://api.weibo.com/2/"
self.app_key = app_key
self.app_secret = app_secret
self.callback_url = callback_url
self.access_token = None
self.expires_in = 0
self._load_token()

def _load_token(self):
    try:
        with open('token.json') as f:
            token_data = json.load(f)
            self.access_token = token_data['access_token']
            self.expires_in = token_data['expires_in']
    except FileNotFoundError:
        self._get_new_token()

def _get_new_token(self):
    auth_url = f"https://api.weibo.com/oauth2/authorize?client_id={self.app_key}&response_type=code&redirect_uri={quote(self.callback_url)}"
    print(f"Please visit this URL to authorize: {auth_url}")
    code = input("Enter the authorization code: ")

    token_url = "https://api.weibo.com/oauth2/access_token"
    data = {
        'client_id': self.app_key,
        'client_secret': self.app_secret,
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': self.callback_url
    }
    response = requests.post(token_url, data=data)
    token_data = response.json()
    self.access_token = token_data['access_token']
    self.expires_in = token_data['expires_in']

    with open('token.json', 'w') as f:
        json.dump(token_data, f)

def _make_request(self, endpoint, method='GET', params=None, files=None):
    if not params:
        params = {}
    params['access_token'] = self.access_token
    url = self.base_url + endpoint

    if method == 'GET':
        response = requests.get(url, params=params)
    else:
        response = requests.post(url, data=params, files=files)

    if response.status_code == 401:  # Token expired
        self._get_new_token()
        return self._make_request(endpoint, method, params, files)

    return response.json()

def post_text(self, text):
    endpoint = "statuses/update.json"
    params = {'status': text}
    return self._make_request(endpoint, 'POST', params)

def post_image(self, text, image_path):
    endpoint = "statuses/upload.json"
    with open(image_path, 'rb') as f:
        files = {'pic': f}
        params = {'status': text}
        return self._make_request(endpoint, 'POST', params, files)

def post_video(self, text, video_path):
    endpoint = "statuses/upload_url_text.json"
    with open(video_path, 'rb') as f:
        video_data = base64.b64encode(f.read()).decode('utf-8')
        params = {
            'status': text,
            'url': f"data:video/mp4;base64,{video_data}"
        }
        return self._make_request(endpoint, 'POST', params)

def get_unread_messages(self):
    endpoint = "remind/unread_count.json"
    return self._make_request(endpoint)['unread']

def reply_comment(self, comment_id, reply_text):
    endpoint = "comments/reply.json"
    params = {
        'cid': comment_id,
        'comment': reply_text
    }
    return self._make_request(endpoint, 'POST', params)
相关文章
|
传感器 编解码 数据处理
毕业设计|基于STM32单片机的水位浑浊度检测设计
毕业设计|基于STM32单片机的水位浑浊度检测设计
2316 0
|
6月前
|
数据采集 人工智能 自然语言处理
舆情监控:如何让AI自动抓取新闻资讯,并生成每日摘要报告?
本文介绍一套AI驱动的自动化舆情监控方案:用站大爷隧道代理(高可用IP轮换)+ OpenClaw(零代码AI Agent)+ 大模型(智能摘要),7×24小时自动抓取、筛选、生成并推送结构化日报,彻底解决人工扫新闻耗时多、漏报频、易被封等问题。(239字)
1748 9
微博批量关注签到发帖脚本,超话发布自动插件,油猴工具实现源码
完整的微博自动化操作油猴脚本实现方案。这个脚本包含批量关注、每日签到、自动发帖和超话发布功能
|
人工智能 自然语言处理 知识图谱
Yuxi-Know:开源智能问答系统,基于大模型RAG与知识图谱技术快速构建知识库
Yuxi-Know是一个结合大模型RAG知识库与知识图谱技术的智能问答平台,支持多格式文档处理和复杂知识关系查询,具备多模型适配和智能体拓展能力。
4448 55
Yuxi-Know:开源智能问答系统,基于大模型RAG与知识图谱技术快速构建知识库
|
Web App开发 自然语言处理 机器人
微博自动发布工具,微博自动发帖机器人,自动发布微博脚本插件
这个微博自动发布工具包含四个主要模块:主控制程序、微博操作类、内容生成器和配置文件
王者荣耀大厅喊话脚本,大厅自动打字发广告插件,按键实现全自动效果分享
这是一款王者荣耀智能喊话软件源码分享。通过插件实现自动在大厅发送文字广告,支持多账号操作与随机话术功能。包含布局创建、按钮事件及循环执行代码逻辑。
|
前端开发 Java 开发者
MVC 架构模式技术详解与实践
本文档旨在全面解析软件工程中经典且至关重要的 MVC(Model-View-Controller) 架构模式。内容将深入探讨 MVC 的核心思想、三大组件的职责与交互关系、其优势与劣势,并重点分析其在现代 Web 开发中的具体实现,特别是以 Spring MVC 框架为例,详解其请求处理流程、核心组件及基本开发实践。通过本文档,读者将能够深刻理解 MVC 的设计哲学,并掌握基于该模式进行 Web 应用开发的能力。
2064 1
微博自动发布脚本,微博批量发布插件,关注私信点赞工具
这是一套微博营销自动化工具源码,可实现多账号同时发布微博、点赞、关注与私信功能,通过随机内容发布和延迟设置
|
算法 数据可视化 测试技术
共学 | 2025年,更加有效地搭建Agent
2024年末,Anthropic写了一篇叫做“Building effective Agents”的文章,针对如何有效的搭建Agent,常见Agent工作流程的几种范式,以及对现在的Code Agent工作模式做了详细的解读。本文结合cookbook+ModelScope的免费Qwen API做了一些中文示例的实践,来更好的理解这篇文章。
5754 7
共学 | 2025年,更加有效地搭建Agent
|
监控 前端开发 应用服务中间件
小游戏源码开发搭建技术栈和服务器配置流程
近些年不同场景游戏层出不穷,现就小游戏开发技术应用及功能详细剖析!

热门文章

最新文章