1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# -*- coding: utf-8 -*-
# @Time : 2022/12/29 15:51
# @Author : 南宫乘风
# @Email : 1794748404@qq.com
# @File : epic.py
# @Software: PyCharm
import json
import time
import requests
from bs4 import BeautifulSoup
def get_free():
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")
text = "今日喜加一 <br>" + 'https://steamstats.cn/xi' + '<br>'
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', '')
oringin = td[6].find('span').string.replace(" ", "").replace('\n', '').replace('\r', '')
text = text + "序号:" + str(
i) + '<br>' + "游戏名称:" + name + '<br>' + "DLC/game:" + gametype + '<br>' + "开始时间:" + start + '<br>' + "结束时间:" + end + '<br>' + "是否永久:" + time + '<br>' + "平台:" + oringin + '<br>'
# print(text)
i++
return text
def send_to_epic_message(text_info):
content = ''.join(text_info)
token = 'xxxxxxxxxxxxxxxxx'
day_time = time.strftime('%Y-%m-%d', time.localtime(time.time()))
title = f'喜加一 免费游戏-{day_time}' # 改成你要的标题内容
error_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) # 获取格式化的时间
url = 'http://www.pushplus.plus/send'
data = {
"token": token, # 密钥
"title": title, # 标题
"content": content, # 发送的信息内容,这里我们是json数组
"template": "markdown" # 数据类型为json
}
body = json.dumps(data).encode(encoding='utf-8')
headers = {'Content-Type': 'application/json'}
request_result = requests.post(url, data=body, headers=headers)
if __name__ == "__main__":
game_info = get_free()
if len(game_info) > 40:
send_to_epic_message(get_free())
|