Python helpers#

The module plonegovbr.socialmedia.utils provides functions to build, add, merge, and read the value of a social_links field, as The social_links value describes it.

No function modifies the links it is given. A function that adds or merges links returns a new list.

Important

Assign the returned list to the field. The database does not notice a stored list changed in place.

Values#

SocialLink

The type of one link: dict[str, str | list[dict[str, str]]].

EMPTY_VALUES

The texts that count as empty in a network id or an address: "", "None", "none", and "null". Leading and trailing spaces are stripped before the comparison.

PATTERNS

The regular expressions that read a username from a profile address, by network id. It has entries for facebook and x, as Computed usernames describes.

extract_username_from_profile#

Returns the username in a profile address.

Parameter

Type

Description

profile

str

A profile address, such as https://x.com/ploneorgbr.

network_id

str

The network, such as x.

Returns

The username that the network's entry in PATTERNS reads from the address. An empty string when the network has no entry, or the address does not match it.