def list_games(platform: str) -> Iterator[Game]: """ Given a supported platform it will provide an iterator of with a subset of data for all games found in the listing service Nintendo of America. Game data --------- * title: str * region: str (NA) * platform: str * nsuid: str (optional) * description: str * free_to_play: bool * genres: List[str] * na_slug: str * players: int * publisher: str * release_date : datetime Parameters ---------- platform: str Valid nintendo platform. Returns ------- Iterator[classes.nintendeals.games.Game]: Partial information of a game provided by NoA. """ for data in search_games(platform=platform): game = Game( title=data["title"], region=NA, platform=platform, nsuid=data.get("nsuid"), ) game.na_slug = data["slug"] game.genres = data.get("categories", []) try: release_date = data["releaseDateMask"].split("T")[0] game.release_date = datetime.strptime(release_date, '%Y-%m-%d') except ValueError: pass try: game.players = int(re.sub(r"[^\d]*", "", data["players"])) except ValueError: game.players = 0 game.description = data.get("description") game.free_to_play = data.get("msrp") == 0.0 game.publisher = data.get("publishers", [None])[0] yield game
def _scrap(url: str) -> Game: response = requests.get(url, allow_redirects=True) soup = BeautifulSoup(response.text, features="html.parser") scripts = list(filter(lambda s: "window.game" in str(s), soup.find_all('script'))) if not scripts: return None script = scripts[0] lines = [line.strip().replace("\",", "") for line in str(script).split("\n") if ':' in line] data = dict(map(lambda line: line.split(': "'), lines)) platform = data["platform"] game = Game( nsuid=data["nsuid"], product_code=data["productCode"], title=_unquote(data["title"]), region=NA, platform=PLATFORMS[platform], ) # Genres game.genres = _unquote(data["genre"]).split(",") game.genres.sort() # Languages game.languages = _class(soup, "languages").split(",") game.languages.sort() # Players try: game.players = int(re.sub(r"[^\d]*", "", _class(soup, "num-of-players"))) except (ValueError, TypeError): game.players = 0 # Release date try: release_date = _itemprop(soup, "releaseDate") game.release_date = datetime.strptime(release_date, '%b %d, %Y') except ValueError: pass # Game size (in MBs) game.size = _itemprop(soup, "romSize") if game.size: game.size, unit = game.size.split(" ") game.size = round(float(game.size) * (1024 if unit == "GB" else 1)) # Other properties game.demo = _aria_label(soup, "Download game demo opens in another window.") is not None game.description = _itemprop(soup, "description", tag="div") game.developer = _itemprop(soup, "manufacturer") game.dlc = _class(soup, "dlc", tag="section") is not None game.free_to_play = data["msrp"] == '0' game.game_vouchers = _aria_label(soup, "Eligible for Game Vouchers") is not None game.online_play = _aria_label(soup, "online-play") is not None game.publisher = _unquote(data["publisher"]) game.save_data_cloud = _aria_label(soup, "save-data-cloud") is not None game.na_slug = _unquote(data["slug"]) # Unknown game.amiibo = None game.iaps = None game.local_multiplayer = None game.voice_chat = None return game