Python通知Epic白嫖游戏信息

每周都有免费游戏 - Epic Games
近期看到Epic在送游戏,目前每周都会有活动白嫖。

身为白嫖党,肯定要操作一下。

游戏列表:Epic Games Store 每周免费游戏(331) | indienova GameDB 游戏库

大致思路:

1、根据网站,获取可 “  白嫖  ”的游戏

2、处理相关信息,组成文本

3、发送到微信上,让我们知道。

1、查询网站

下面网页,会发布最新免费,可白嫖的游戏。我们爬取这些信息,进行判断

游戏列表:Epic Games Store 每周免费游戏(331) | indienova GameDB 游戏库

2、代码编写

1.我们爬取网页的数据

2.获取网页中所有游戏的信息

3.判断游戏信息是最新编辑的

4.汇总信息进行发送到微信

相关实例代码

# -*- coding: utf-8 -*-
# @Time    : 2022/12/29 16:33
# @Author  : 南宫乘风
# @Email   : 1794748404@qq.com
# @File    : epic_all.py
# @Software: PyCharm
import json
import re
import time

import requests
from bs4 import BeautifulSoup


def get_url_info():
    url = 'https://indienova.com/gamedb/list/121/p/1'
    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'}
    res = requests.get(url, headers=headers).text
    return res


def check_epci_info(game_info_list):
    list_content = []
    for i in game_info_list:
        game_time = i['game_time']
        if '小时前' in game_time[0]:
            content = f"中文名称:{i['game_zh']}  <br/>" \
                      f"英文名称:{i['game_en']} <br/>" \
                      f"领取时间:{i['game_start']} <br/>" \
                      f"发布时间:{i['game_time']}<br/><br/>"
            list_content.append(content)
    return list_content


def parse_web_page(res):
    soup = BeautifulSoup(res, "html.parser")
    res.encode('UTF-8').decode('UTF-8')
    div_class = soup.find(name='div', attrs={"id": "portfolioList"})
    # print(div_class[0])
    game_name = div_class.find_all(name='div', attrs={"class": "col-xs-12 col-sm-6 col-md-4 user-game-list-item"})
    list_game = str(game_name).split('<div class="col-xs-12 col-sm-6 col-md-4 user-game-list-item">')
    game_info_list = []
    for i in list_game[1:]:
        dict_info = {}
        # print('----------------------------------------------------------------------------------')
        game = BeautifulSoup(i, "html.parser")
        game_all_info = game.find(name='h4')
        game_name_zh = game_all_info.find_all(name='a')
        game_name_en = game_all_info.find_all(name='small')
        game_name_zh = re.findall(r'>(.+?)<', str(game_name_zh))
        game_name_en = re.findall(r'>(.+?)<', str(game_name_en))
        # print(game_name_zh, game_name_en)
        game_start_end = game.find(name='p', attrs={"class": "intro"})
        game_start_end_new = game_start_end.find_all(name='span')
        game_edit_time = game.find(name='p', attrs={"class": "text-date"})
        game_edit_time_new = game_edit_time.find_all(name='small')
        game_edit_time_new = str(game_edit_time_new).replace(" ", "").replace("\n", " ")

        game_start_end_new = re.findall(r'>(.+?)<', str(game_start_end_new))
        game_edit_time_new = re.findall(r'>(.+?)<', str(game_edit_time_new))
        dict_info["game_zh"] = game_name_zh
        dict_info["game_en"] = game_name_en
        dict_info["game_start"] = game_start_end_new
        dict_info["game_time"] = game_edit_time_new
        game_info_list.append(dict_info)

    # print(game_start_end_new,game_edit_time_new)
    return game_info_list


def send_to_epic_message(list_content):
    content = ''.join(list_content) + '\nhttps://indienova.com/gamedb/list/121/p/1'
    token = 'tokenxxxxxxxxxxxxxxxxxxxx'
    day_time = time.strftime('%Y-%m-%d', time.localtime(time.time()))
    title = f'Epic免费游戏-{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)


# print(request_result)  # <Response [200]>

if __name__ == '__main__':
    res = get_url_info()
    game_info_list = parse_web_page(res)
    list_content = check_epci_info(game_info_list)
    send_to_epic_message(list_content)

3、发送平台(pushplus)

微信公众号关注

pushplus(推送加)-微信消息推送平台

获取token进行配置即可。

4、定时任务

我们要把脚本部署到Linux操作环境 上。

首先记得安装依赖。pip install 模块

定时任务,每天10点运行一次。

0 10 * * * /usr/bin/python3 /opt/epic_send.py

5、增加 喜加一 的资讯通知

网站为steam free game,steam free promotion - Steam Stats

# -*- 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())

 

 

参考文档:python获取steam/epic喜加一信息并自动发送到微信 - 知乎

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南宫乘风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值