# -*- coding: utf-8 -*-
# @Time    : 2022/12/29 15:51
# @Author  : 南宫乘风
# @Email   : 1794748404@qq.com
# @File    : epic.py
# @Software: PyCharm
from datetime import datetime
import json
import re
import time

import requests
from bs4 import BeautifulSoup


def is_friday():
    today = datetime.today()
    return today.weekday() == 4  # Monday is 0 and Sunday is 6, so Friday is 4



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 = "今日喜加一  :" + 'https://store.epicgames.com/en-US/free-games' +'\n'

    tbody = soup.find('tbody')
    tr = tbody.find_all('tr')
    i = 1
    for tr in tr:
        td = tr.find_all('td')
        a_tags = td[6].find_all('a')
        for a in a_tags:
            href_value = a.get('href')
        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) + '\n' + "游戏名称：" + name + '\n'
                + "DLC/game：" + gametype + '\n'
                + "开始时间：" + start + '\n'
                + "结束时间：" + end + '\n'
                + "是否永久：" + time + '\n'
                + "平台：" + oringin + '\n'
                + "URL：" + href_value + '\n'
                )

        # print(text)
        i=i+1

    return text

if __name__ == "__main__":
   print(get_free())
    # if len(game_info) > 40:

        # send_to_epic_message(get_free())