Merge pull request #180 from stijndcl/fix/free-games

Fix free games
pull/181/head v3.7.1
Stijn De Clercq 2023-12-25 23:04:30 +01:00 committed by GitHub
commit f181a7a833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 10 deletions

1
.tool-versions 100644
View File

@ -0,0 +1 @@
python 3.9.5

View File

@ -15,7 +15,7 @@ from didier.utils.types.string import abbreviate
__all__ = ["SEPARATOR", "FreeGameEmbed"] __all__ = ["SEPARATOR", "FreeGameEmbed"]
SEPARATOR = " • Free • " SEPARATOR = " is free to claim at "
def _get_store_info(store: str) -> tuple[Optional[str], discord.Colour]: def _get_store_info(store: str) -> tuple[Optional[str], discord.Colour]:
@ -48,7 +48,7 @@ def _get_store_info(store: str) -> tuple[Optional[str], discord.Colour]:
class FreeGameEmbed(EmbedPydantic): class FreeGameEmbed(EmbedPydantic):
"""Embed for free games""" """Embed for free games"""
dc_identifier: int id: int
link: str link: str
title: str title: str
@ -103,15 +103,13 @@ class FreeGameEmbed(EmbedPydantic):
inline=False, inline=False,
) )
embed.add_field(name="Open in browser", value=f"[{self.link}]({self.link})") embed.add_field(name="Open in browser", value=self.link)
if self.store_page.xdg_open_url is not None: if self.store_page.xdg_open_url is not None:
embed.add_field( embed.add_field(name="Open in app", value=self.store_page.xdg_open_url)
name="Open in app", value=f"[{self.store_page.xdg_open_url}]({self.store_page.xdg_open_url})"
)
else: else:
embed.title = self.name embed.title = self.name
embed.add_field(name="Open in browser", value=f"[{self.link}]({self.link})") embed.add_field(name="Open in browser", value=self.link)
embed.url = self.link embed.url = self.link

View File

@ -16,7 +16,7 @@ __all__ = ["fetch_free_games"]
async def fetch_free_games(http_session: ClientSession, database_session: AsyncSession) -> list[FreeGameEmbed]: async def fetch_free_games(http_session: ClientSession, database_session: AsyncSession) -> list[FreeGameEmbed]:
"""Get a fresh list of free games""" """Get a fresh list of free games"""
url = "https://pepeizqdeals.com/?call_custom_simple_rss=1&csrp_cat=12" url = "https://pepeizqdeals.com/rss-en.xml"
async with http_session.get(url) as response: async with http_session.get(url) as response:
if response.status != HTTPStatus.OK: if response.status != HTTPStatus.OK:
logger.error("Free games GET-request failed with status code %d." % response.status) logger.error("Free games GET-request failed with status code %d." % response.status)
@ -34,7 +34,7 @@ async def fetch_free_games(http_session: ClientSession, database_session: AsyncS
game = FreeGameEmbed.model_validate(entry) game = FreeGameEmbed.model_validate(entry)
games.append(game) games.append(game)
game_ids.append(game.dc_identifier) game_ids.append(game.id)
# Filter out games that we already know # Filter out games that we already know
filtered_ids = await filter_present_games(database_session, game_ids) filtered_ids = await filter_present_games(database_session, game_ids)
@ -42,7 +42,7 @@ async def fetch_free_games(http_session: ClientSession, database_session: AsyncS
# Insert new games into the database # Insert new games into the database
await add_free_games(database_session, filtered_ids) await add_free_games(database_session, filtered_ids)
games = list(filter(lambda x: x.dc_identifier in filtered_ids, games)) games = list(filter(lambda x: x.id in filtered_ids, games))
# Look up additional info # Look up additional info
for game in games: for game in games: