zoukankan      html  css  js  c++  java
  • 薅羊毛须及时 多平台微信线报提醒脚本

    说明

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

    需求

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

    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 + '
    ' + 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)
    
    
  • 相关阅读:
    数据库中随机返回n条数据的方法
    sql中NULL之恨
    数据库性能的查询优化特刊待续
    sql中exists替换in的区别
    代码的效率问题看一下代码
    检测数据库性能的方法
    Linux随堂1
    设置网页的图标
    C# 线程、timer例句
    转:1.2 Oracle表空间的操作
  • 原文地址:https://www.cnblogs.com/aosky/p/12036258.html
Copyright © 2011-2022 走看看