def get_icon( self, asset: Asset, given_size: Literal['thumb', 'small', 'large'], ) -> Optional[bytes]: """Returns the byte data of the requested icon If the icon can't be found it returns None. If the icon is found cached locally it's returned directly. If not, all icons of the asset are queried from coingecko and cached locally before the requested data are returned. """ if not asset.has_coingecko(): return None needed_path = self.iconfile_path(asset, given_size) if needed_path.is_file(): with open(needed_path, 'rb') as f: image_data = f.read() return image_data # else query coingecko for the icons and cache all of them if self._query_coingecko_for_icon(asset) is False: return None if not needed_path.is_file(): return None with open(needed_path, 'rb') as f: image_data = f.read() return image_data
def get_icon( self, asset: Asset, ) -> Optional[bytes]: """Returns the byte data of the requested icon If the icon can't be found it returns None. If the icon is found cached locally it's returned directly. If not, all icons of the asset are queried from coingecko and cached locally before the requested data are returned. """ # First search custom icons custom_icon_path = self.custom_iconfile_path(asset) if custom_icon_path is not None: with open(custom_icon_path, 'rb') as f: image_data = f.read() return image_data # Then our only chance is coingecko if not asset.has_coingecko(): return None needed_path = self.iconfile_path(asset) if needed_path.is_file(): with open(needed_path, 'rb') as f: image_data = f.read() return image_data # else query coingecko for the icons and cache all of them if self._query_coingecko_for_icon(asset) is False: return None if not needed_path.is_file(): return None with open(needed_path, 'rb') as f: image_data = f.read() return image_data