def main(): """Fetches current free games from the store.""" api = EpicGamesStoreAPI() free_games = api.get_free_games( )['data']['Catalog']['searchStore']['elements'] for game in free_games: game_name = game['title'] game_thumbnail = None # Can be useful when you need to also show the thumbnail of the game. # Like in Discord's embeds for example, or anything else. # Here I showed it just as example and won't use it. for image in game['keyImages']: if image['type'] == 'Thumbnail': game_thumbnail = image['url'] game_price = game['price']['totalPrice']['fmtPrice']['originalPrice'] game_promotions = game['promotions']['promotionalOffers'] upcoming_promotions = game['promotions']['upcomingPromotionalOffers'] if not game_promotions and upcoming_promotions: # Promotion is not active yet, but will be active soon. promotion_data = upcoming_promotions[0]['promotionalOffers'][0] start_date_iso, end_date_iso = (promotion_data['startDate'][:-1], promotion_data['endDate'][:-1]) # Remove the last "Z" character so Python's datetime can parse it. start_date = datetime.fromisoformat(start_date_iso) end_date = datetime.fromisoformat(end_date_iso) print('{} ({}) will be free from {} to {} UTC.'.format( game_name, game_price, start_date, end_date)) else: print('{} ({}) is FREE now.'.format(game_name, game_price))
def main(): """ Print all games in filter range """ api = EpicGamesStoreAPI() games = api.fetch_store_games( product_type='games/edition/base|bundles/games|editors', # Default filter in store page. count=30, sort_by='releaseDate', sort_dir='DESC', release_date="[2019-09-16T14:02:36.304Z,2019-09-26T14:02:36.304Z]", with_price=True, ) print('API Response:\n', json.dumps(games, indent=4))
def main(): api = EpicGamesStoreAPI() getgames = api.get_free_games() freegames = getgames['data']['Catalog']['searchStore']['elements'] for game in freegames: gamename = game['title'] gameprice = game['price']['totalPrice']['fmtPrice']['originalPrice'] gamepromotions = game['promotions']['promotionalOffers'] upcomingpromotions = game['promotions']['upcomingPromotionalOffers'] if not gamepromotions and upcomingpromotions: promotiondata = upcomingpromotions[0]['promotionalOffers'][0] startdateis, enddateis = (promotiondata['startDate'][:-1], promotiondata['endDate'][:-1]) startdate = datetime.fromisoformat(startdateis) enddate = datetime.fromisoformat(enddateis) print('{} ({}) will become free from {} to {}.'.format( gamename, gameprice, startdate, enddate)) else: print('{} ({}) is currently free.'.format(gamename, gameprice))
def main(): """ Prints offer ID and developer for every offer of the first product in mapping """ api = EpicGamesStoreAPI() namespace, slug = list(api.get_product_mapping().items())[0] first_product = api.get_product(slug) offers = [] for page in first_product['pages']: if page.get('offer') is not None: offers.append(OfferData(page['namespace'], page['offer']['id'])) offers_data = api.get_offers_data(*offers) for offer_data in offers_data: data = offer_data['data']['Catalog']['catalogOffer'] developer_name = '' for custom_attribute in data['customAttributes']: if custom_attribute['key'] == 'developerName': developer_name = custom_attribute['value'] print('Offer ID:', data['id'], '\nDeveloper Name:', developer_name)
#!/usr/bin/env python3 from epicstore_api import EpicGamesStoreAPI, OfferData import dateparser api = EpicGamesStoreAPI() free = api.get_free_games() for free_data in free['data']['Catalog']['searchStore']['elements']: if type(free_data['promotions']) is dict: if len(free_data['promotions']['promotionalOffers']) == 1: date_debut = dateparser.parse( free_data['promotions']['promotionalOffers'][0] ['promotionalOffers'][0]['startDate']).date() date_fin = dateparser.parse( free_data['promotions']['promotionalOffers'][0] ['promotionalOffers'][0]['endDate']).date() else: date_debut = dateparser.parse( free_data['promotions']['upcomingPromotionalOffers'][0] ['promotionalOffers'][0]['startDate']).date() date_fin = dateparser.parse( free_data['promotions']['upcomingPromotionalOffers'][0] ['promotionalOffers'][0]['endDate']).date() print(free_data['title'], ': du ', date_debut, ' au ', date_fin) print('\n')
from epicstore_api import EpicGamesStoreAPI from datetime import datetime import json api = EpicGamesStoreAPI() def freegameListEpic(): #* cria lista de jogos gratis da epicGames no momento free_games = api.get_free_games( )['data']['Catalog']['searchStore']['elements'] with open('return/FreeGames.json', 'w') as json_file: json.dump(free_games, json_file, indent=4) with open('return/FreeGames.json') as f: free = json.load(f) with open('return/FreeGame.json') as f: fre = json.load(f) o = 0 i = 0 for Game in free: o = o + 1 freegame = Game["title"] print(f"{o} Name: {freegame}") result = {"Title": freegame} fre[f"Game{o}"] = result
async def epic_free_game_check(): # Set the free-games channel freeGamesChannel = bot.get_channel(bot.freegameschannelid) # Lookup free-games from the Epic Store API api = EpicGamesStoreAPI() free_games = api.get_free_games( )['data']['Catalog']['searchStore']['elements'] # Loop through all games in the result for game in free_games: # Confirm the game has an active promotion, we won't post past or future promos if game['promotions']: if game['promotions']['promotionalOffers']: game_name = game['title'] game_description = game['description'] game_slug = game['productSlug'] game_url = 'https://www.epicgames.com/store/en-US/p/' + game[ 'productSlug'] game_price = "~~{}~~ Free".format( game['price']['totalPrice']['fmtPrice']['originalPrice']) game_thumbnail = None for image in game['keyImages']: if image['type'] == 'Thumbnail': game_thumbnail = image['url'] promotion_data = game['promotions']['promotionalOffers'][0][ 'promotionalOffers'][0] end_date_iso = promotion_data['endDate'][:-1] end_date = datetime.fromisoformat(end_date_iso) end_date_formatted = custom_strftime('%A, %b {S}, %Y', end_date) # Pull additional information about the game's rating gameRatings = api.get_product_reviews( 'EPIC_' + game['productSlug'] )['data']['OpenCritic']['productReviews'] gameRatingInfo = "{} ({})".format( gameRatings['openCriticScore'], gameRatings['award']) # Check to see if we've already seen this free-game before cur = con.cursor() cur.execute( "SELECT * FROM epicGames WHERE game=? AND end_date=?", ( game_name, end_date, )) gameCheck = cur.fetchone() # If the SQL result is none, it's safe to assume we haven't seen the game before and it's okay to write to discord if gameCheck is None: # Insert the game into the epicGames table so we know we've seen it cur = con.cursor() cur.execute("INSERT INTO epicGames VALUES(?,?,?,?)", (game_name, game_slug, game_url, end_date)) con.commit() # Post about the game to discord in the free-games channel embed = discord.Embed(title="Free Game on Epic Games", url=game_url, color=0x007bff) embed.set_thumbnail(url=game_thumbnail) embed.add_field(name=game_name, value=game_description, inline=False) embed.add_field(name="Expires", value=end_date_formatted, inline=True) embed.add_field(name="Price", value=game_price, inline=True) embed.add_field(name="OpenCritic Rating", value=gameRatingInfo, inline=False) await freeGamesChannel.send(embed=embed)
def main(): api = EpicGamesStoreAPI() with pytest.raises(EGSException): api.get_product('this_slug_does_not_exist') satisfactory_page = api.get_product('satisfactory') assert satisfactory_page['namespace'] == 'crab'
from epicstore_api import EpicGamesStoreAPI, OfferData import pandas as pd import datetime API=EpicGamesStoreAPI() def get_games():#FIXME set defauls store country games=API.get_free_games()['data']['Catalog']['searchStore']['elements']#games is a python list of games, each item in that list is a dict #nice_data.to_csv('out.csv')#TODO remove debug lines free_games=[] for game in games: if is_free_game(game): print(clean_game_data(game)) free_games.append(clean_game_data(game)) print('-'*50) return free_games def clean_game_data(data): clean_data={#TODO get developer and publisher info from customAttributes and photo urls "title": data["title"], "subtitle": "Subtitles are yet to come! This is temporary", "promotion_end_time": datetime.datetime.strptime(data["promotions"]["promotionalOffers"][0]["promotionalOffers"][0]["endDate"],"%Y-%m-%dT%H:%M:%S.%fZ") } return clean_data def is_free_game(game):#FIXME I need some testing, should evaluate to true if a game has a "promotions" disctionary and then the promotionalOffers key contains a list at least 1 in length. if game["promotions"] is not None: if len(game["promotions"]["promotionalOffers"]) > 0: return True return False