本帖最后由 hxy310 于 2023-9-5 01:05 编辑
根据楼主的代码,我改良了一下,将token放入了Actions secrets and variables,这样不会暴露token,防止有人利用token推送垃圾信息,并且我将Server酱换成了pushplus,大家可以选择性使用。
需要打开你的储存库-Settings-Secrets and variables-Actions-New repository secret Name填TOKEN,底下的值就将你的推送秘钥粘贴进去就行了。
[Shell] 纯文本查看 复制代码 name: Happy_Plus_One
on:
workflow_dispatch:
schedule:
- cron: 0 1 * * * #国际标准时间,北京时间+8
jobs:
my_job:
runs-on: ubuntu-latest
steps:
- name: 'checkout codes' #检测代码
uses: actions/checkout@v2
- name: 'set up python' #配置python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: requirements #配置库
run: |
python -m pip install --upgrade pip
pip install beautifulsoup4
- name: 'Epic/steam happy +1' #运行py
run: |
python happy_plus_one.py ${{ secrets.TOKEN }}
[Asm] 纯文本查看 复制代码 import sys
import requests
from bs4 import BeautifulSoup
# PushPlus推送模块
def pushplus(_item, _message):
token = sys.argv[1]
api = 'http://www.pushplus.plus/send'
_d = {
"token": token,
"title": _item,
"content": _message
}
req = requests.post(api, data=_d)
print(req.text)
# 爬取代码
url = 'https://steamstats.cn/xi'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.41'}
r = requests.get(url, headers=headers)
r.raise_for_status()
r.encoding = r.apparent_encoding
soup = BeautifulSoup(r.text, "html.parser")
tbody = soup.find('tbody')
tr = tbody.find_all('tr')
i = 1
for tr in tr:
td = tr.find_all('td')
name = td[1].string.strip().replace('\n', '').replace('\r', '')
gametype = td[2].string.replace(" ", "").replace('\n', '').replace('\r', '')
start = td[3].string.replace(" ", "").replace('\n', '').replace('\r', '')
end = td[4].string.replace(" ", "").replace('\n', '').replace('\r', '')
time = td[5].string.replace(" ", "").replace('\n', '').replace('\r', '')
origin = td[6].find('span').string.replace(" ", "").replace('\n', '').replace('\r', '')
sp = str(td[6]).split('"')
http = sp[3]
desp = "序号:" + str(i) + '\n\r' + "游戏名称:" + name + '\n\r' + "类型:" + gametype + '\n\r' + "开始时间:" + start + '\n\r' + "结束时间:" + end + '\n\r' + "是否永久:" + time + '\n\r' + "平台:" + origin + '\n\r' + "链接:" + http + '\n\r'
# 推送
pushplus("今日喜加一", desp)
print(desp)
如果想使用Server酱,将我第二段的代码第1到第15行替换即可。
[Python] 纯文本查看 复制代码 import sys
import requests
from bs4 import BeautifulSoup
#Server酱推送模块,PUSH_KEY替换自己的
def send_message_fangtang(_item,_message):
token = sys.argv[1]
api = 'https://sctapi.ftqq.com/' + token + '.send'
_d = {
"title": _item,
"desp": _message
}
req = requests.post(api,data = _d)
#print(req.text)
|