Как получить productSluge из api.get_free_games()
Я создаю дискорд бота, который по запросу выдаёт бесплатные на данный момент игры из EpicGame Store. За основу взял код из примера и переделал под вывод бота. В footer хочу положить ссылку на страницу для получения игры. Для этого мне нужно получить "productSluge" из api.get_free_games() или получить ссылку иным способом.
Так не работает
api.get_free_games()['productSluge']
Использую epicstore_api
Мне нужна часть в скобках
https://www.epicgames.com/store/ru/product/<Эта часть>/home
Или полная ссылка
Полная команда дискорд бота:
@bot.command()
async def free(ctx):
"""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']
# print(game_thumbnail)
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)
will = ('Игра будет бесплатна с {} по {} UTC.'.format(
start_date, end_date
))
emb = discord.Embed(title=game_name + game_price, description=will, colour=col['AQUA'])
emb.set_footer(text='url')
emb.set_image(url=game_thumbnail)
await ctx.send(embed=emb)
else:
emb = discord.Embed(title='Сейчас БЕСПЛАТНО!', description=game_name + game_price, colour=col['GOLD'])
emb.set_footer(text='url')
emb.set_image(url=game_thumbnail)
await ctx.send(embed=emb)
Ответы (1 шт):
Автор решения: Ghost
→ Ссылка
Работает если добавить в цикл
for game in free_games:
game_slug = game['productSlug']