Skip to content

Commit

Permalink
Merge pull request #180 from stijndcl/fix/free-games
Browse files Browse the repository at this point in the history
Fix free games
  • Loading branch information
stijndcl authored Dec 25, 2023
2 parents 17b6eba + dc4ee08 commit f181a7a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python 3.9.5
12 changes: 5 additions & 7 deletions didier/data/embeds/free_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

__all__ = ["SEPARATOR", "FreeGameEmbed"]

SEPARATOR = " • Free • "
SEPARATOR = " is free to claim at "


def _get_store_info(store: str) -> tuple[Optional[str], discord.Colour]:
Expand Down Expand Up @@ -48,7 +48,7 @@ def _get_store_info(store: str) -> tuple[Optional[str], discord.Colour]:
class FreeGameEmbed(EmbedPydantic):
"""Embed for free games"""

dc_identifier: int
id: int
link: str
title: str

Expand Down Expand Up @@ -103,15 +103,13 @@ def to_embed(self, **kwargs) -> discord.Embed:
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:
embed.add_field(
name="Open in app", value=f"[{self.store_page.xdg_open_url}]({self.store_page.xdg_open_url})"
)
embed.add_field(name="Open in app", value=self.store_page.xdg_open_url)
else:
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

Expand Down
6 changes: 3 additions & 3 deletions didier/data/rss_feeds/free_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

async def fetch_free_games(http_session: ClientSession, database_session: AsyncSession) -> list[FreeGameEmbed]:
"""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:
if response.status != HTTPStatus.OK:
logger.error("Free games GET-request failed with status code %d." % response.status)
Expand All @@ -34,15 +34,15 @@ async def fetch_free_games(http_session: ClientSession, database_session: AsyncS

game = FreeGameEmbed.model_validate(entry)
games.append(game)
game_ids.append(game.dc_identifier)
game_ids.append(game.id)

# Filter out games that we already know
filtered_ids = await filter_present_games(database_session, game_ids)

# Insert new games into the database
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
for game in games:
Expand Down

0 comments on commit f181a7a

Please sign in to comment.