吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3820|回复: 22
上一主题 下一主题
收起左侧

[Python 转载] 微博某人更新推送给微信消息

   关闭 [复制链接]
跳转到指定楼层
楼主
英雄初本涩 发表于 2022-4-9 10:53 回帖奖励
用的第三方:https://wxpusher.zjiecode.com/docs/#/ 注册说明请查看文档

源码如下:
import requests
import json
import threading

s = requests.session()
headers = {
    'Content-Type':'application/json'
}
preList = []
newList = []
def getFilstList():
    global newList
    global preList
        #这里value填你想要的人的UID
    url = 'https://m.weibo.cn/api/container/getIndex?type=uid&value=6367430139&containerid=1076036367430139&since_id'

    res = s.get(url)
    r = json.loads(res.text)
    preList = newList
    newList = r['data']['cards']
    preIds = []
    newIds = []
    for item in preList:
        if item['mblog']:
            preIds.append(item['mblog']['id'])

    for item in newList:
        if item['mblog']:
            newIds.append(item['mblog']['id'])
    if len(newIds) and len(preIds):
        new_id = set(newIds).difference(set(preIds))
        for item in list(new_id):
            getLongText(item)

# 获取微博内容
def getLongText(id):
    url = 'https://m.weibo.cn/statuses/extend?id={}'.format(id)
    res = s.get(url)
    try:
        r = json.loads(res.text)
        send(r['data']['longTextContent'])
        print('推送成功,{}'.format(url))
    except:
        print('获取全文出错,跳过···{}'.format(url))
def send(content):
    url = 'http://wxpusher.zjiecode.com/api/send/message'
    data = {
      "appToken":"AT_**",#填自己在wxpusher申请的token
      "content": content,
      "summary":"温馨提示",#消息摘要,显示在微信聊天页面或者模版消息卡片上,限制长度100,可以不传,不传默认截取content前面的内容。
      "contentType":2,#内容类型 1表示文字  2表示html(只发送body标签内部的数据即可,不包括body标签) 3表示markdown
      "topicIds":[ #发送目标的topicId,是一个数组!!!,也就是群发,使用uids单发的时候, 可以不传。
      ],
      "uids":[#发送目标的UID,是一个数组。注意uids和topicIds可以同时填写,也可以只填写一个。
          # 想推送给谁,UID在wxpusher后台看,如果推送的人比较多可以用官方的获取用户接口
          "UID_HzegkwY7SKAT1C634A3A3ZnDZK"
      ],
      "url":"https://m.weibo.cn/statuses/extend?id=4755736296948252" #原文链接,可选参数
    }
    res = s.post(url,data=json.dumps(data),headers=headers)
    print(res.text)

def timerMonitor():
    getFilstList()
    t = threading.Timer(10, timerMonitor)
    t.start()
if __name__ == '__main__':
    timerMonitor()

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
chowhong 发表于 2022-4-10 09:23
本帖最后由 chowhong 于 2022-4-10 10:07 编辑

请问这里报错了是什么原因?

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='m.weibo.cn', port=443): Max retries exceeded with url: /api/container/getIndex?type=uid&value=6367430139&containerid=1076036367430139&since_id (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1129)')))

====
装了下面三个包
pip install ndg-httpsclientpip install pyopensslpip install pyasn1

把xx软件关掉,就没有报错了。(可能上面三个包都不用装)
推荐
poor567 发表于 2022-5-14 18:18
出现这样报错,何解?
Traceback (most recent call last):
  File "D:/微博推送.py", line 68, in <module>
    timerMonitor()
  File "D:/微博推送.py", line 64, in timerMonitor
    getFilstList()
  File "D:/微博推送.py", line 28, in getFilstList
    if item['mblog']:
KeyError: 'mblog'
3#
kingskype 发表于 2022-4-9 12:04
4#
zhaomingzhi 发表于 2022-4-9 12:15
这个还是比较实用的
5#
llllin233 发表于 2022-4-9 13:25
哇,终于找到可以微信推送的了,十分感谢
6#
oxding 发表于 2022-4-9 13:51
def timerMonitor():
    getFilstList()
    t = threading.Timer(10, timerMonitor)
    t.start()
if __name__ == '__main__':
    timerMonitor()

能讲讲每句话的意思吗
7#
无缺i 发表于 2022-4-9 16:26
oxding 发表于 2022-4-9 13:51
def timerMonitor():
    getFilstList()
    t = threading.Timer(10, timerMonitor)

main方法都看不懂,建议你先了解了解python基础
8#
chowhong 发表于 2022-4-10 08:22
感谢分享。真是视奸利器啊
9#
kwccer 发表于 2022-4-10 09:36
能否改成推送头条的信息,原来关注过一个公众号,叫知更鸟鸣,可以推送头条关于股市的推送,现在关闭了,不知道这个可能实现,谢谢
10#
dnightx7 发表于 2022-4-10 11:22
呜呜呜 我太笨了 跟着文档都不会用
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-3 01:51

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表