摸鱼办+每日电影推荐+一步步教你创建第一个云函数
本帖最后由 ▓innovator 于 2021-12-8 09:20 编辑pushplsh账号创建
1.登陆pushplsh
2.选择一对多推(复制Token) 替换'token':'填写你的pushplus',
3.创建一个组群
4.查看二维码并扫描关注
5.代码里面'topic':'2' 替换成自己创建的组群编码,如我创建的是5,就是'topic':'5'
代码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+"<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.split('>').split('<')
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(','), '%Y-%m-%d')
dayname = s.split(',').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.微信收到推送消息
下面是运行截图
本帖最后由 tompanda 于 2021-12-10 16:24 编辑
推送钉钉
钉钉机器人安全设置 关键字摸鱼提醒
# -*- coding: utf8 -*-
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+"\n"
k=int(k)+1
url = "http://wufazhuce.com/"
wd=GetInfo(url)
moyu=BuildContent(wd)
str1=moyu + "每日新电影"+str1
#url = "http://pushplus.hxtrip.com/send"
#data={'token':'21c28ee68f91400fb634e97dce55bb94','title':'每日提示','content':str1,'template':'html','topic':'2'}
url = "https://oapi.dingtalk.com/robot/send?access_token=钉钉token"
data={"msgtype": "text","text": {"content": str1}}
print(data)
headers = {'Content-Type': 'application/json'}
result = requests.post(url=url,headers=headers,data=json.dumps(data))
print(result.text)
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.split('>').split('<')
return word
def BuildContent(word):
title = "#【摸鱼提醒】"
today = datetime.datetime.now()
Today = "\n今天是" + str(today.year) + "年" + str(today.month) + "月" + str(today.day) + "日\n"
Weekday = "距离本周周末还有" + str(6 - today.weekday() - 1) + "天\n"
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(','), '%Y-%m-%d')
dayname = s.split(',').replace("\n>", "")
if int((that - today).days + 1) > 0:
OtherHappy += "距离" + dayname + "还有" + str((that - today).days + 1) + "天" + '\n'
text = "工作再累,一定不要忘记摸鱼哦!有事没事起身去茶水间,去厕所,去廊道走走别老在工位上坐着,钱是老板的,但命是自己的\n"
HappyContent = title + Today+ text +Weekday + OtherHappy + (word)
#print(HappyContent)
return HappyContent 哈哈哈哈,这个有意思 大佬,怎么推送到企业微信,能否帮忙修改下 填写对应的Token没反应,测试是成功的 不错不错,有意思 这个可有意思了 !!!!!!! 小沐沐警官 发表于 2021-12-7 17:47
填写对应的Token没反应,测试是成功的
我也是呢 zkl 发表于 2021-12-7 18:28
我也是呢
求解求解 怎么推送到微信或者钉钉?求解 现在的云函数还是免费的吗/
好像有些功能收费了