aosky

说明

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

需求

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

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)

分类:

技术点:

相关文章:

  • 2022-01-08
  • 2022-01-12
  • 2021-11-19
  • 2021-07-29
  • 2021-08-09
  • 2021-12-11
  • 2021-09-13
  • 2021-06-06
猜你喜欢
  • 2021-11-09
  • 2021-09-19
  • 2021-12-06
  • 2021-08-03
  • 2021-11-10
  • 2022-01-02
相关资源
相似解决方案