Пример #1
0
 def _load_source(self, *args):
     """ Before downloading remote image, first check for existing thumbnail """
     # Differentiating between None and '' here to handle on_load being triggered multiple times
     if self.thumbnail_path is None:
         self.thumbnail_path = get_thumbnail_if_exists(self.source) or ''
         if self.thumbnail_path:
             logger.debug(f'Found {self.source} in cache: {self.thumbnail_path}')
             self.source = self.thumbnail_path
     super()._load_source(*args)
Пример #2
0
def preload_thumnails(model, min_rank='family', depth=0):
    logger.info(f'Processing: {model.rank} {model.name} at depth {depth}')
    thumnail_exists = model.photo_url and get_thumbnail_if_exists(
        model.photo_url)

    # Only preload images that can be redistributed under Creative Commons
    if model.has_cc_photo and not thumnail_exists:
        generate_thumbnail_from_url(model.photo_url, 'large')
        generate_thumbnail_from_url(model.thumbnail_url, 'small')
        sleep(IMAGE_DOWNLOAD_DELAY)

    if model.rank not in [min_rank, 'species', 'subspecies']:
        n_children = len(model.child_taxa)
        for i, child in enumerate(model.child_taxa):
            # Skip child if it's already loaded in another category
            if child.id not in PRELOAD_TAXA:
                logger.info(f'Child {i}/{n_children}')
                preload_thumnails(child, min_rank, depth=depth + 1)
Пример #3
0
 def on_load(self, *args):
     """ After loading, cache the downloaded image for future use, if not previously done """
     if not get_thumbnail_if_exists(self.source):
         cache_async_thumbnail(self, size=self.thumbnail_size)
Пример #4
0
def get_any_thumbnail_if_exists(source: str, size: str = 'small') -> str:
    """ Get the path of a thumbnail stored inside either an atlas or the thumbnail cache """
    return get_atlas_thumbnail_if_exists(source, size) or get_thumbnail_if_exists(source)