Code Duplication    Length = 21-21 lines in 2 locations

collexions.py 1 location

@@ 195-215 (lines=21) @@
192
        except Exception as e: logging.error(f"Error during unpin for '{library_name}': {e}")
193
    logging.info(f"Unpinning complete. Unpinned {unpinned_count} collections.")
194
195
def get_active_special_collections(config):
196
    """Determines which 'special' collections are active based on current date."""
197
    current_date = datetime.now().date()
198
    active_titles = []
199
    special_configs = config.get('special_collections', [])
200
    if not isinstance(special_configs, list): logging.warning("'special_collections' not list."); return []
201
    for special in special_configs:
202
        if not isinstance(special, dict) or not all(k in special for k in ['start_date', 'end_date', 'collection_names']): continue
203
        s_date, e_date, names = special.get('start_date'), special.get('end_date'), special.get('collection_names')
204
        if not isinstance(names, list) or not s_date or not e_date: continue
205
        try:
206
            start = datetime.strptime(s_date, '%m-%d').replace(year=current_date.year).date()
207
            end = datetime.strptime(e_date, '%m-%d').replace(year=current_date.year).date()
208
            end_excl = end + timedelta(days=1)
209
            is_active = (start <= current_date < end_excl) if start <= end else (start <= current_date or current_date < end_excl)
210
            if is_active: active_titles.extend(n for n in names if isinstance(n, str))
211
        except ValueError: logging.error(f"Invalid date format in special: {special}. Use MM-DD.")
212
        except Exception as e: logging.error(f"Error process special {names}: {e}")
213
    unique_active = list(set(active_titles))
214
    if unique_active: logging.info(f"Active special collections: {unique_active}")
215
    return unique_active
216
217
def get_fully_excluded_collections(config, active_special_collections):
218
    """Combines explicit exclusions and inactive special collections."""

ColleXions.py 1 location

@@ 195-215 (lines=21) @@
192
        except Exception as e: logging.error(f"Error during unpin for '{library_name}': {e}")
193
    logging.info(f"Unpinning complete. Unpinned {unpinned_count} collections.")
194
195
def get_active_special_collections(config):
196
    """Determines which 'special' collections are active based on current date."""
197
    current_date = datetime.now().date()
198
    active_titles = []
199
    special_configs = config.get('special_collections', [])
200
    if not isinstance(special_configs, list): logging.warning("'special_collections' not list."); return []
201
    for special in special_configs:
202
        if not isinstance(special, dict) or not all(k in special for k in ['start_date', 'end_date', 'collection_names']): continue
203
        s_date, e_date, names = special.get('start_date'), special.get('end_date'), special.get('collection_names')
204
        if not isinstance(names, list) or not s_date or not e_date: continue
205
        try:
206
            start = datetime.strptime(s_date, '%m-%d').replace(year=current_date.year).date()
207
            end = datetime.strptime(e_date, '%m-%d').replace(year=current_date.year).date()
208
            end_excl = end + timedelta(days=1)
209
            is_active = (start <= current_date < end_excl) if start <= end else (start <= current_date or current_date < end_excl)
210
            if is_active: active_titles.extend(n for n in names if isinstance(n, str))
211
        except ValueError: logging.error(f"Invalid date format in special: {special}. Use MM-DD.")
212
        except Exception as e: logging.error(f"Error process special {names}: {e}")
213
    unique_active = list(set(active_titles))
214
    if unique_active: logging.info(f"Active special collections: {unique_active}")
215
    return unique_active
216
217
def get_fully_excluded_collections(config, active_special_collections):
218
    """Combines explicit exclusions and inactive special collections."""