trustcafe-api-wrapper/wrappers/post/create_post.py
2026-04-01 21:31:15 +01:00

46 lines
No EOL
1.6 KiB
Python

def create_post(post_text, parent_path='/', blur_label=None, card_url=None, collaborative=False):
"""
Creates a new post.
Args:
post_text (str): The text content of the post.
parent_path (str, optional): The parent path for the post, default is None.
blur_label (str, optional): An optional label for blurring the post content.
card_url (str, optional): An optional URL to include as a card in the post.
collaborative (bool, optional): Whether the post is collaborative, default is False.
Returns:
dict: A dictionary containing the job name and payload for creating the post
that will be processed by the API client wrapper function.
"""
parent_pksk = None
if parent_path == '/':
parent_pksk = 'maintrunk#maintrunk'
else:
parent_path = parent_path.strip('/')
entity, slug = parent_path.split('/')
if entity == 'branch':
entity = 'subwiki'
if entity not in ['userprofile', 'subwiki']:
raise ValueError(f"Invalid parent entity: {entity}. Must be 'userprofile' or 'branch'.")
parent_pksk = f"{entity}#{slug}"
return {
"job_function": "post.create",
"payload": {
"blurLabel": blur_label,
"cardUrl": card_url,
"postText": post_text,
"collaborative": collaborative,
"parent": {
"pk": parent_pksk,
"sk": parent_pksk
}
}
}