patch_all()
from gevent.pool import Pool

from newslynx.lib import dates
from newslynx.lib import url
from newslynx.lib import text
from newslynx.lib import html
from newslynx.lib import stats
from newslynx.models import URLCache, ThumbnailCache
from newslynx import settings
from newslynx.exc import RequestError
from newslynx.constants import METRIC_FACET_KEYS

# the url cache object
url_cache = URLCache()
thumbnail_cache = ThumbnailCache()

# a pool to multithread url_cache.
url_cache_pool = Pool(settings.URL_CACHE_POOL_SIZE)


def prepare_links(links=[], domains=[]):
    """
    Prepare links to be tested against content items.
    """
    if len(domains):
        _links = []
        for l in links:
            if any([d in l for d in domains]):
                _links.append(l)
        links = _links