43 lines
No EOL
1.4 KiB
Python
43 lines
No EOL
1.4 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: The payload for creating the post, which can be passed to
|
|
the API client's run_job method with 'post.create'.
|
|
"""
|
|
|
|
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 {
|
|
"blurLabel": blur_label,
|
|
"cardUrl": card_url,
|
|
"postText": post_text,
|
|
"collaborative": collaborative,
|
|
"parent": {
|
|
"pk": parent_pksk,
|
|
"sk": parent_pksk
|
|
}
|
|
} |