Source code for eodag.plugins.crunch.filter_latest_tpl_name

# -*- coding: utf-8 -*-
# Copyright 2018, CS GROUP - France,
# This file is part of EODAG project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import re

from eodag.plugins.crunch.base import Crunch
from eodag.utils.exceptions import MisconfiguredError

logger = logging.getLogger("eodag.plugins.crunch.filter_latest_tpl_name")

[docs]class FilterLatestByName(Crunch): """FilterLatestByName cruncher Filter Search results to get only the latest product, based on the name of the product :param config: Crunch configuration, must contain : - `name_pattern` : product name pattern :type config: dict """ NAME_PATTERN_CONSTRAINT = re.compile(r"\(\?P<tileid>\\d\{6\}\)")
[docs] def __init__(self, config): super(FilterLatestByName, self).__init__(config) name_pattern = config.pop("name_pattern") if not raise MisconfiguredError( "Name pattern should respect the regex: {}".format( self.NAME_PATTERN_CONSTRAINT.pattern ) ) self.name_pattern = re.compile(name_pattern)
[docs] def proceed(self, product_list, **search_params): """Execute crunch: Filter Search results to get only the latest product, based on the name of the product :param products: A list of products resulting from a search :type products: list(:class:`~eodag.api.product._product.EOProduct`) :returns: The filtered products :rtype: list(:class:`~eodag.api.product._product.EOProduct`) """ logger.debug("Starting products filtering") processed = [] filtered = [] for product in product_list: match = self.name_pattern.match(["title"]) if match: tileid ="tileid") if tileid not in processed: logger.debug( "Latest product found for tileid=%s: date=%s", tileid,["startTimeFromAscendingNode"], ) filtered.append(product) processed.append(tileid) else: logger.debug("Latest product already found for tileid=%s", tileid) else: logger.warning( "The name of the product %r as returned by the search plugin does not match the name " "pattern expected by the cruncher %s. Name of the product: %s. Name pattern expected: " "%s", product, self.__class__.__name__,["title"], self.name_pattern, )"Finished filtering products. %s resulting products", len(filtered)) return filtered