code: 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]
  
file_path: textacy/scripts/fetch_wiki_lang_snippets.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import argparse
  import datetime
  import io
  import logging
  import os
  import random
  import re
  import sys
  import time
  import warnings
  import wikipedia
  from cld2 import detect
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling a global function with example usage: get_snippets(lang, n, featured, good, timeout) and returns: all_snippets