本帖最后由 ▓innovator 于 2021-12-8 09:20 编辑
pushplsh账号创建
1.登陆pushplsh
2.选择一对多推(复制Token) 替换'token':'填写你的pushplus',
3.创建一个组群
4.查看二维码并扫描关注
5.代码里面'topic':'2' 替换成自己创建的组群编码,如我创建的是5,就是'topic':'5'
代码[Python] 纯文本查看 复制代码 import re
import requests
import json
import datetime
def main_handler(event, context):
uel= "https://www.80s.tw/"
aa=requests.get(uel)
aa.encoding="utf-8"
selector = aa.text
getHtml = re.compile(r'<li>.*<a href="/movie/.*" title="\S*')
selector = re.findall(getHtml, selector)
str1 = ""
k=1
for i in selector:
var = i.split('title="')
str1 += str(k)+'.'+var[1]+"<br/>"
k=int(k)+1
url = "http://wufazhuce.com/"
wd=GetInfo(url)
moyu=BuildContent(wd)
str1=moyu + "<h3>每日新电影</h3>"+str1
url = "http://pushplus.hxtrip.com/send"
data={'token':'填写你的pushplus','title':'每日提示','content':str1,'template':'html','topic':'2'}
requests.post(url=url, data=json.dumps(data))
def GetInfo(url):
headers = {"content-type": "application/json",
"User-Agent": 'Mozilla/5.0 (X11;Ubuntu;Linux x86_64; rv:22.0) Gecko/20100101 Firefox'}
page = requests.get(url, headers=headers).text
getHtml = re.compile(r'<a href="http://wufazhuce.com/one/.*')
word = re.findall(getHtml, page)
word=word[1].split('>')[1].split('<')[0]
return word
def BuildContent(word):
title = "【摸鱼提醒】</br>"
today = datetime.datetime.now()
Today = "今天是" + str(today.year) + "年" + str(today.month) + "月" + str(today.day) + "日\n"+ '</br>'
Weekday = "距离本周周末还有" + str(6 - today.weekday() - 1) + "天\n"+ '</br>'
OtherHappy = ""
map = ["2022-01-01,元旦", "2022-01-31,春节", "2022-04-03,清明", "2022-04-30,五一",
"2022-06-03,端午", "2022-09-10,中秋", "2022-10-01,国庆"]
for s in map:
that = datetime.datetime.strptime(s.split(',')[0], '%Y-%m-%d')
dayname = s.split(',')[1].replace("\n", "")
if int((that - today).days + 1) > 0:
OtherHappy += "距离" + dayname + "还有" + str((that - today).days + 1) + "天" + '</br>'
text = "工作再累,一定不要忘记摸鱼哦!有事没事起身去茶水间,去厕所,去廊道走走别老在工位上坐着,钱是老板的,但命是自己的" + '</br>'
HappyContent = title + Today + text +Weekday + OtherHappy + (word+"</br>")
print(HappyContent)
return HappyContent
云函数创建
1.选择地区,点击新建
2.选择自定义模板---运行环境3.6--完成
3.将代码粘贴进去,点击部署--测试
4.测试成功后可以看到执行日志情况
5.创建触发器,定时发送信息
6.微信收到推送消息
下面是运行截图
|