def stop_criteria(index, date, flags):
    """Check stop criteria

    Args:
        index (int): index of current element
        date (datetime): date of current element
        flags (dict): List of flags:
            from_date: use only requests after specified date
            to_date: use only requests before specified date
            limit: use N requests from the beginning of file or specified date

    Returns:
        bool: returns true if stop criteria is achieved
    """
    result = False
    if 'to_date' in flags:
        result = date >= flags['to_date']
    if 'limit' in flags:
        result = index >= flags['limit']
    return result
