薅羊毛须及时 多平台微信线报提醒脚本

说明

闲着也是闲着,一堆废旧手机好几个微信账号,每天薅个早餐钱吧。

需求

监控线报网站有线报更新发送微信信息提醒。

from wxpy import *
import platform,sqlite3,time,requests
from bs4 import BeautifulSoup

#微信机器人配置
console_qr=(False if platform.system() == 'Windows' else True)
bot = Bot('bot.pkl', console_qr=console_qr)
tuling = Tuling('图灵接口自动回复')
my_friend = bot.friends()
tt = bot.groups().search('群名称')[0]

@bot.register(tt)
def send(msg):
    tt.send(msg)

@bot.register(my_friend)
def tuling_reply(msg):
    tuling.do_reply(msg)

@bot.register(msg_types=FRIENDS)
def auto_accept_friends(msg):
    new_friend = msg.card.accept()
    new_friend.send('您好,有什么可以帮您的吗?')

#创建数据库
#只采集链接和标题发送到微信群
conn = sqlite3.connect("./xianbao.db", check_same_thread=False)
cursor = conn.cursor()
try:
    sql = 'CREATE TABLE xianbao(id integer primary key autoincrement, via text NOT NULL UNIQUE,title text,pubtime datetime) '
    cursor.execute(sql)
except Exception as e:
    print("表已存在")
finally:
    conn.commit()

#线报采集以科学刀为例
def kxdao():
    site = '科学刀'
    r = requests.get('https://www.kxdao.net/forum-42-1.html')
    html = r.text
    bs = BeautifulSoup(html,'lxml')
    links = bs.findAll('a',class_='s xst')
    for link in links:
        url = link['href']
        title = link.text
        pubtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        msg = title + '\n' + url
        w = cursor.execute('INSERT INTO "xianbao" ("via", "title", "pubtime") VALUES (?, ?, ?)',
                       [url,title, pubtime])
        if w == True:
            print(msg)
            conn.commit()

#设置间隔时间五分钟
while 1:
    kxdao()
    time.sleep(300)

薅羊毛须及时 多平台微信线报提醒脚本

上一篇:Python编程:RabbitMQ消息队列


下一篇:微信第三方平台代公众号发起网页授权 48001 api unauthorized 问题