-
Notifications
You must be signed in to change notification settings - Fork 8
/
egs.py
21 lines (19 loc) · 1.03 KB
/
egs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests
import sopel
import datetime
@sopel.module.commands('egs', 'egsfree')
def egs(bot, trigger):
url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=en-US&country=US&allowCountries=US"
res = requests.get(url).json()
freenow = []
upcomingfree = []
for x in res['data']['Catalog']['searchStore']['elements']:
if not x['promotions']:
continue
if x['promotions']['promotionalOffers']:
freenow.append("{} [until {}]".format(x['title'], datetime.datetime.strptime(x['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate'], "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%m/%d")))
else:
if not x['promotions']['upcomingPromotionalOffers']:
continue
upcomingfree.append("{} [starts {}]".format(x['title'], datetime.datetime.strptime(x['promotions']['upcomingPromotionalOffers'][0]['promotionalOffers'][0]['startDate'], "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%m/%d")))
bot.say("Free now: {} | Upcoming: {}".format(", ".join(freenow), ", ".join(upcomingfree)))