code: def minify_urls(filepath, ext='asc', url_regex=None, output_ext='.urls_minified', access_token=None):
      
      access_token = access_token or secrets.bitly.access_token
      output_ext = output_ext or ''
      url_regex = regex.compile(url_regex) if isinstance(url_regex, str) else url_regex
      filemetas = []
      for filemeta in find_files(filepath, ext=ext):
          filemetas += [filemeta]
          altered_text = ''
          with open(filemeta['path'], 'rt') as fin:
              text = fin.read()
          end = 0
          for match in url_regex.finditer(text):
              url = match.group()
              start = match.start()
              altered_text += text[:start]
              resp = requests.get('https://api-ssl.bitly.com/v3/shorten?access_token={}&longUrl={}'.format(
                  access_token, url), allow_redirects=True, timeout=5)
              js = resp.json()
              short_url = js['shortUrl']
              altered_text += short_url
              end = start + len(url)
          altered_text += text[end:]
          with open(filemeta['path'] + (output_ext or ''), 'wt') as fout:
              fout.write(altered_text)
      return altered_text
docs: Use bitly or similar minifier to shrink all URLs in text files within a folder structure.
  
      Used for the NLPIA manuscript directory for Manning Publishing
  
      bitly API: https://dev.bitly.com/links.html
  
      Args:
        path (str): Directory or file path
        ext (str): File name extension to filter text files by. default='.asc'
        output_ext (str): Extension to append to filenames of altered files default='' (in-place replacement of URLs)
  
      FIXME: NotImplementedError! Untested!