說明
閑著也是閑著馒索,一堆廢舊手機(jī)好幾個(gè)微信賬號(hào),每天薅個(gè)早餐錢吧富岳。
需求
監(jiān)控線報(bào)網(wǎng)站有線報(bào)更新發(fā)送微信信息提醒器赞。
依賴庫
wxpy bs4
pip install 搞定
from wxpy import *
import platform,sqlite3,time,requests
from bs4 import BeautifulSoup
#微信機(jī)器人配置
console_qr=(False if platform.system() == 'Windows' else True)
bot = Bot('bot.pkl', console_qr=console_qr)
tuling = Tuling('圖靈接口自動(dòng)回復(fù)')
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('您好,有什么可以幫您的嗎启搂?')
#創(chuàng)建數(shù)據(jù)庫
#只采集鏈接和標(biāo)題發(fā)送到微信群
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()
#線報(bào)采集以科學(xué)刀為例
def kxdao():
site = '科學(xué)刀'
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()
#設(shè)置間隔時(shí)間五分鐘
while 1:
kxdao()
time.sleep(300)