EPIC限免提示

2022-11-15,

通过云函数每周定时推送限免内容到手机

import datetime
import requests requests.packages.urllib3.disable_warnings() # date = datetime.datetime.strptime(i['effectiveDate'][:-5], "%Y-%m-%dT%H:%M:%S") def get_game():
dic = {'namespace': [], 'offers': []}
url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=zh-CN&country=CN&allowCountries=CN,JP"
header = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Mobile Safari/537.36",
}
res = requests.get(url=url, headers=header)
if res.status_code == 200:
js = res.json()['data']['Catalog']['searchStore']['elements']
now = datetime.datetime.now() - datetime.timedelta(days=7)
for i in js:
date = datetime.datetime.strptime(i['effectiveDate'][:-5], "%Y-%m-%dT%H:%M:%S")
if date < now:
continue
else:
dic['namespace'].append(i['items'][0]['namespace'])
dic['offers'].append(i['id']) utc_date = datetime.datetime.strptime(i['effectiveDate'], "%Y-%m-%dT%H:%M:%S.%fZ")
local_date = utc_date + datetime.timedelta(days=7)
print(
'游戏名:' + i['title'] + '\n\t游戏描述:' + i['description'] + '\n\t游戏厂商:' + i['seller'][
'name'] + '\n\t开始时间:' +
i['effectiveDate'] + '\n\t结束时间:' + str(local_date) + '\n\t游戏原价:' + i['price']['totalPrice']['fmtPrice'][
'originalPrice'], '\n\t折后价:' + i['price']['totalPrice']['fmtPrice']['discountPrice'],
'\n\tnamespace:%s \toffers:%s' % (i['items'][0]['namespace'], i['id']))
return dic
else:
print('get请求错误:', res.text)
return dic if __name__ == '__main__':
get_game()

EPIC限免提示的相关教程结束。

《EPIC限免提示.doc》

下载本文的Word格式文档,以方便收藏与打印。