diff --git a/didier/data/embeds/free_games.py b/didier/data/embeds/free_games.py index a6b8421..6ef94d8 100644 --- a/didier/data/embeds/free_games.py +++ b/didier/data/embeds/free_games.py @@ -102,8 +102,9 @@ class FreeGameEmbed(EmbedPydantic): inline=False, ) + embed.add_field(name="Open in browser", value=f"[{self.link}]({self.link})") + if self.store_page.xdg_open_url is not None: - embed.add_field(name="Open in browser", value=f"[{self.link}]({self.link})") embed.add_field( name="Open in app", value=f"[{self.store_page.xdg_open_url}]({self.store_page.xdg_open_url})" diff --git a/didier/data/scrapers/common.py b/didier/data/scrapers/common.py index 1fa973e..963496e 100644 --- a/didier/data/scrapers/common.py +++ b/didier/data/scrapers/common.py @@ -6,6 +6,7 @@ from bs4 import BeautifulSoup, Tag __all__ = ["GameStorePage", "parse_open_graph_tags"] +# TODO make this an ABC that all other store pages implement instead @dataclass class GameStorePage: """Dataclass for information on a game's store page""" @@ -15,7 +16,7 @@ class GameStorePage: title: str xdg_open_url: Optional[str] = None url: Optional[str] = None - discount_expiry: Optional[int] = None + discount_expiry: Optional[int] = None # TODO discounted_price: Optional[str] = None original_price: Optional[str] = None discount_percentage: Optional[str] = None diff --git a/didier/data/scrapers/steam.py b/didier/data/scrapers/steam.py index 2099cd1..39d0837 100644 --- a/didier/data/scrapers/steam.py +++ b/didier/data/scrapers/steam.py @@ -32,15 +32,15 @@ def _shorten_url(url: str) -> str: if match is None or not match.groups(): return url - return f"https://s.team/a/{match.groups()[0]}/" + return f"https://s.team/a/{match.groups()[0]}" def _parse_xdg_open_url(url: str) -> Optional[str]: match = re.search(r"/app/(\d+)/", url) - if match is None or match.group() is None: + if match is None or not match.groups(): return None - return f"steam://store/{match.group()}" + return f"steam://store/{match.groups()[0]}" def _get_steam_discounts(soup: BeautifulSoup) -> Optional[_PriceInfo]: @@ -110,8 +110,8 @@ async def get_steam_webpage_info(http_session: ClientSession, url: str) -> Optio page_tags.url = url page_tags.title = _clean_title(page_tags.title) - page_tags.url = _shorten_url(page_tags.url) page_tags.xdg_open_url = _parse_xdg_open_url(page_tags.url) + page_tags.url = _shorten_url(page_tags.url) price_info = _get_steam_discounts(soup)