(lang, n, featured, good, timeout)
return all_snippets[:n]
Args:
        lang (str)
        n (int)
        featured (Dict[str, :class:`wikipediaapi.WikipediaPage`] or None)
        good (Dict[str, :class:`wikipediaapi.WikipediaPage`] or None)
        timeout (int)

    Returns:
        List[str]
Args:
        lang (str)
        n (int)
        featured (Dict[str, :class:`wikipediaapi.WikipediaPage`] or None)
        good (Dict[str, :class:`wikipediaapi.WikipediaPage`] or None)
        timeout (int)
Args : lang ( str ) n ( int ) featured ( Dict [ str : class : wikipediaapi . WikipediaPage ] or None ) good ( Dict [ str : class : wikipediaapi . WikipediaPage ] or None ) timeout ( int )
def get_snippets(lang, n, featured, good, timeout):
    """
    Args:
        lang (str)
        n (int)
        featured (Dict[str, :class:`wikipediaapi.WikipediaPage`] or None)
        good (Dict[str, :class:`wikipediaapi.WikipediaPage`] or None)
        timeout (int)

    Returns:
        List[str]
    """
    wikipedia.set_lang(lang)
    all_snippets = []
    seen_pages = set()
    start_time = time.time()
    with tqdm(total=n, unit="snippets", unit_scale=True, leave=True) as pbar:
        while len(all_snippets) < n and (time.time() - start_time) < timeout:
            titles = []
            if featured:
                try:
                    featured_titles = get_category_members_from_lang_links(
                        featured, lang, "Category:Featured_articles"
                    )
                    titles.extend(featured_titles)
                except Exception:
                    logging.exception("unable to get featured article titles")
                    continue
                finally:
                    featured = None
            if good:
                try:
                    good_titles = get_category_members_from_lang_links(
                        good, lang, "Category:Good_articles"
                    )
                    titles.extend(good_titles)
                except Exception:
                    logging.exception("unable to get good article titles")
                    continue
                finally:
                    good = None
            try:
                random_titles = wikipedia.random(min(25, n))
                titles.extend(random_titles)
            except Exception:
                logging.exception("unable to get random page titles")
                continue
            for title in titles:
                if title in seen_pages or "/" in title:
                    continue
                try:
                    page = wikipedia.page(title=title)
                except Exception:
                    logging.debug("unable to fetch wiki page '%s'", title)
                    continue
                try:
                    snippets = extract_snippets_from_page(page, exclude_en=lang != "en")
                except Exception:
                    logging.exception("unable to extract snippets from page '%s'", title)
                    continue
                all_snippets.extend(snippets)
                pbar.update(len(snippets))
                # break out of random title loop early if we can
                if len(all_snippets) >= n:
                    break
    return all_snippets[:n]
def get_snippets ( lang , n , featured , good , timeout ) : wikipedia . set_lang ( lang ) all_snippets = [ ] seen_pages = set ( ) start_time = time . time ( ) with tqdm ( total = n , unit = "snippets" , unit_scale = True , leave = True ) as pbar : while len ( all_snippets ) < n and ( time . time ( ) - start_time ) < timeout : titles = [ ] if featured : try : featured_titles = get_category_members_from_lang_links ( featured , lang , "Category:Featured_articles" ) titles . extend ( featured_titles ) except Exception : logging . exception ( "unable to get featured article titles" ) continue finally : featured = None if good : try : good_titles = get_category_members_from_lang_links ( good , lang , "Category:Good_articles" ) titles . extend ( good_titles ) except Exception : logging . exception ( "unable to get good article titles" ) continue finally : good = None try : random_titles = wikipedia . random ( min ( 25 , n ) ) titles . extend ( random_titles ) except Exception : logging . exception ( "unable to get random page titles" ) continue for title in titles : if title in seen_pages or "/" in title : continue try : page = wikipedia . page ( title = title ) except Exception : logging . debug ( "unable to fetch wiki page '%s'" , title ) continue try : snippets = extract_snippets_from_page ( page , exclude_en = lang != "en" ) except Exception : logging . exception ( "unable to extract snippets from page '%s'" , title ) continue all_snippets . extend ( snippets ) pbar . update ( len ( snippets ) ) # break out of random title loop early if we can if len ( all_snippets ) >= n : break return all_snippets [ : n ]