get_parent_pksk_from_path utils function

This commit is contained in:
simonwt 2026-04-01 22:14:57 +01:00
parent 4f14965ba1
commit 010d54bc87
3 changed files with 18 additions and 15 deletions

1
utils/__init__.py Normal file
View file

@ -0,0 +1 @@
from .get_parent_pksk_from_path import get_parent_pksk_from_path

View file

@ -0,0 +1,14 @@
def get_parent_pksk_from_path(parent_path):
if parent_path == '/':
return 'maintrunk#maintrunk'
entity, slug = parent_path.strip('/').split('/')
if entity == 'branch':
entity = 'subwiki'
elif entity != 'user':
entity = 'userprofile'
if entity not in ['userprofile', 'subwiki']:
raise ValueError(f"Invalid parent entity: {entity}. Must be 'userprofile' or 'branch'.")
return f"{entity}#{slug}"

View file

@ -1,3 +1,5 @@
from utils.get_parent_pksk_from_path import get_parent_pksk_from_path
def create_post(post_text, parent_path='/', blur_label=None, card_url=None, collaborative=False): def create_post(post_text, parent_path='/', blur_label=None, card_url=None, collaborative=False):
""" """
Creates a new post. Creates a new post.
@ -14,22 +16,8 @@ def create_post(post_text, parent_path='/', blur_label=None, card_url=None, coll
that will be processed by the API client wrapper function. that will be processed by the API client wrapper function.
""" """
parent_pksk = None parent_pksk = get_parent_pksk_from_path(parent_path)
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 { return {
"job_function": "post.create", "job_function": "post.create",