def _convert_to_wakat_format(seeder_struct):
    """
    Convert Seeder's structure to the internal structure used at frontend.

    Args:,
        seeder_struct (dict): Dictionary with Seeder data.

    Returns:
        obj: :class:`Model`.
    """
    def pick_active(seeder_struct, what):
        """
        From the list of dicts, choose only first of such, that contains
        ``"active": True`` item.

        If not found, just pick the first.

        Args:
            seeder_struct (dict): Dict with bunch of data.
            what (str): What key to use in `seeder_struct` to identify the
                list of dicts.

        Returns:
            dict: Active or first dict.
        """
        items = seeder_struct.get(what)

        if not items:
            return None

        if not (isinstance(items, list) or isinstance(items, tuple)):
            items = [items]

        active_items = [item for item in items if item.get("active")]

        if not active_items:
            return items[0]

        return active_items[0]

    if not seeder_struct:
        return None

    # pick active seed and active publisher
    active_seed = pick_active(seeder_struct, "seeds")
    publisher_contact = pick_active(
        seeder_struct.get("publisher", {}),
        "contacts"
    )

    # seed contains `url`, which is used as primary key - if no seed is found,
    # it is meaningless to continue
    if not active_seed:
        active_seed = pick_active(seeder_struct, "seed")  # alt naming
        if not active_seed:
            return None

    # create the model and fill it with data
    model = Model()
    model.url = active_seed["url"]
    model.issn = seeder_struct.get("issn")
    model.title_tags = seeder_struct.get("name")
    model.publisher_tags = seeder_struct.get("publisher", {}).get("name")
    model.annotation_tags = seeder_struct.get("comment")  # annotation?

    # conspect = None  # TODO: !

    if publisher_contact:
        model.place_tags = publisher_contact.get("address")

    # rules are stored in custom subdictionary
    rules = {}
    rules["frequency"] = str(seeder_struct.get("frequency"))

    _add_if_set(rules, "budget", active_seed.get("budget"))
    _add_if_set(rules, "youtube", active_seed.get("youtube"))
    _add_if_set(rules, "calendars", active_seed.get("calendars"))
    _add_if_set(rules, "javascript", active_seed.get("javascript"))
    _add_if_set(rules, "local_traps", active_seed.get("local_traps"))
    _add_if_set(rules, "gentle_fetch", active_seed.get("gentle_fetch"))
    _add_if_set(rules, "global_reject", active_seed.get("global_reject"))

    model.rules = rules

    # add source info
    for key in model.keys():
        val = getattr(model, key)
        if val and "tags" in key:
            setattr(model, key, [{"val": val, "source": "Seeder"}])

    return model.get_mapping()
def _convert_to_wakat_format ( seeder_struct ) : def pick_active ( seeder_struct , what ) : items = seeder_struct . get ( what ) if not items : return None if not ( isinstance ( items , list ) or isinstance ( items , tuple ) ) : items = [ items ] active_items = [ item for item in items if item . get ( "active" ) ] if not active_items : return items [ 0 ] return active_items [ 0 ] if not seeder_struct : return None active_seed = pick_active ( seeder_struct , "seeds" ) publisher_contact = pick_active ( seeder_struct . get ( "publisher" , { } ) , "contacts" ) if not active_seed : active_seed = pick_active ( seeder_struct , "seed" ) if not active_seed : return None model = Model ( ) model . url = active_seed [ "url" ] model . issn = seeder_struct . get ( "issn" ) model . title_tags = seeder_struct . get ( "name" ) model . publisher_tags = seeder_struct . get ( "publisher" , { } ) . get ( "name" ) model . annotation_tags = seeder_struct . get ( "comment" ) if publisher_contact : model . place_tags = publisher_contact . get ( "address" ) rules = { } rules [ "frequency" ] = str ( seeder_struct . get ( "frequency" ) ) _add_if_set ( rules , "budget" , active_seed . get ( "budget" ) ) _add_if_set ( rules , "youtube" , active_seed . get ( "youtube" ) ) _add_if_set ( rules , "calendars" , active_seed . get ( "calendars" ) ) _add_if_set ( rules , "javascript" , active_seed . get ( "javascript" ) ) _add_if_set ( rules , "local_traps" , active_seed . get ( "local_traps" ) ) _add_if_set ( rules , "gentle_fetch" , active_seed . get ( "gentle_fetch" ) ) _add_if_set ( rules , "global_reject" , active_seed . get ( "global_reject" ) ) model . rules = rules for key in model . keys ( ) : val = getattr ( model , key ) if val and "tags" in key : setattr ( model , key , [ { "val" : val , "source" : "Seeder" } ] ) return model . get_mapping ( )
Convert Seeder's structure to the internal structure used at frontend.

    Args:,
        seeder_struct (dict): Dictionary with Seeder data.

    Returns:
        obj: :class:`Model`.