Skip to content

muck_out.derived

ActorHeaderInfo

Bases: BaseModel

Derived information suitable to be displayed in a header line.

Parameters:

Name Type Description Default
id str

id of the actor, can be assumed to be globally unique.

required
avatar_url str | None

The url of the avatar to use for the actor

None
name str | None

Display name of the actor

None
identifier str

Identifier to display for the actor

required
html_url str | None

Location of a html representation of the actor

None
Source code in muck_out/derived/actor_header_info.py
class ActorHeaderInfo(BaseModel):
    """Derived information suitable to be displayed in a header line."""

    model_config = ConfigDict(
        serialize_by_alias=True,
        extra="forbid",
        field_title_generator=lambda field_name, field_info: "",
        validate_by_name=True,
    )

    id: str = Field(
        examples=["https://actor.example/alice/some/id"],
        description="id of the actor, can be assumed to be globally unique.",
    )

    avatar_url: Annotated[
        str | None,
        Field(
            default=None,
            examples=["https://actor.example/static/alice-avatar.png"],
            description="The url of the avatar to use for the actor",
            alias="avatarUrl",
        ),
    ]

    name: HtmlStringOrNone = Field(
        default=None,
        examples=["Alice"],
        description="Display name of the actor",
    )

    identifier: str = Field(
        examples=["acct:alice@actor.example"],
        description="Identifier to display for the actor",
    )

    html_url: Annotated[
        str | None,
        Field(
            default=None,
            examples=["https://actor.example/@alice"],
            description="Location of a html representation of the actor",
            alias="htmlUrl",
        ),
    ]

ObjectMetaInfo

Bases: BaseModel

Derived information suitable to be displayed in a header line.

Parameters:

Name Type Description Default
id str

id of the object, can be assumed to be globally unique.

required
html_url str | None

Location of a html representation of the object

None
published datetime | None

Moment of this object being published

None
updated datetime | None

Moment of this object being updated

None
Source code in muck_out/derived/object_meta_info.py
class ObjectMetaInfo(BaseModel):
    """Derived information suitable to be displayed in a header line."""

    model_config = ConfigDict(
        serialize_by_alias=True,
        extra="forbid",
        field_title_generator=lambda field_name, field_info: "",
        validate_by_name=True,
    )

    id: str = Field(
        examples=["https://actor.example/alice/some/id"],
        description="id of the object, can be assumed to be globally unique.",
    )

    html_url: Annotated[
        str | None,
        Field(
            default=None,
            examples=["https://actor.example/@alice/some/ud"],
            description="Location of a html representation of the object",
            alias="htmlUrl",
        ),
    ]

    published: datetime | None = Field(
        default=None,
        description="Moment of this object being published",
    )

    updated: datetime | None = Field(
        default=None,
        description="Moment of this object being updated",
    )

actor_to_header_info

actor_to_header_info(actor: Actor) -> ActorHeaderInfo

Turns an Actor object into a reduced version suitable to display in a header lien for this actor.

>>> from muck_out.testing.examples import actor
>>> result = actor_to_header_info(actor)
>>> print(result.model_dump_json(indent=2))
{
  "id": "http://abel/actor/AFKb0cQunSBv1fC7sWbQYg",
  "avatarUrl": "https://dev.bovine.social/assets/bull-horns.png",
  "name": "The kitty",
  "identifier": "acct:kitty@abel",
  "htmlUrl": "http://abel/@kitty"
}
Source code in muck_out/derived/__init__.py
def actor_to_header_info(actor: Actor) -> ActorHeaderInfo:
    """Turns an [Actor][muck_out.types.Actor] object into a reduced version
    suitable to display in a header lien for this actor.

    ```python
    >>> from muck_out.testing.examples import actor
    >>> result = actor_to_header_info(actor)
    >>> print(result.model_dump_json(indent=2))
    {
      "id": "http://abel/actor/AFKb0cQunSBv1fC7sWbQYg",
      "avatarUrl": "https://dev.bovine.social/assets/bull-horns.png",
      "name": "The kitty",
      "identifier": "acct:kitty@abel",
      "htmlUrl": "http://abel/@kitty"
    }

    ```
    """
    avatar_url = actor.icon.get("url") if actor.icon else None
    html_url = determine_html_url(actor.url)
    return ActorHeaderInfo(
        id=actor.id,
        name=actor.name,
        identifier=actor.identifiers[0],
        avatar_url=avatar_url,
        html_url=html_url,
    )