Comment create

This commit is contained in:
simonwt 2026-03-31 12:00:49 +01:00
parent 499c5aee98
commit 620553ea14
4 changed files with 56 additions and 16 deletions

View file

@ -2,15 +2,24 @@
Intended use (not working yet but testing.py does) Intended use (not working yet but testing.py does)
''' ```python
import trustcafeapi import trustcafeapiwrapper, os
import os, simplejson as json
API = trustcafeapi.APIClient( API = trustcafeapiwrapper.APIClient(
client_id=os.getenv("client_id"), client_id=os.getenv("client_id"),
client_secret=os.getenv("client_secret"), client_secret=os.getenv("client_secret")
debug=True
) )
''' profile = API.run_job('userprofile.get', "simon-little")
```
## Debates
1. Not sure about the name `jobs` and `run_job`. Requests is an
existing package dependency though. `tasks` seems to broard. I'm sure
there's probably an already existing name that I can't articulate how
to find.
2. Should these `job` be called with dot notation? Or with slashes? Or
something else? Is it okay to have these as strings?
3. Should we do validation in the `jobs` or let the server do that all?

1
jobs/comment/__init__.py Normal file
View file

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

13
jobs/comment/create.py Normal file
View file

@ -0,0 +1,13 @@
def create(API, payload: dict) -> dict:
"""
Creates a new comment in the API.
Args:
payload (dict): The data for the new post.
Returns:
dict: The comment data.
"""
print(f"Creating a new comment with payload: {payload}")
comment_data = API.make_request("POST", "content", "commentcreate", data=payload, authenticate=True)
return comment_data

View file

@ -31,12 +31,13 @@ if not API.is_token_valid():
with open("token_data.json", "w") as f: with open("token_data.json", "w") as f:
json.dump(tokendata, f, indent=4) json.dump(tokendata, f, indent=4)
# print("-----------Get a user profile----------------")
# profile = API.run_job('userprofile.get', "simon-little") # profile = API.run_job('userprofile.get', "simon-little")
# print(profile) # print(profile)
# print("-----------------------------") # print("-------------- Get a branch -----------------")
# branch = API.run_job('branch.get', "music") # branch = API.run_job('branch.get', "music")
# print(branch) # print(branch)
# print("-----------------------------") # print("-------------- Get a post -------------------")
# post = API.run_job('post.get', "1774875037-170a46a9") # post = API.run_job('post.get', "1774875037-170a46a9")
# print(post) # print(post)
# print("-----------------------------") # print("-----------------------------")
@ -45,15 +46,31 @@ if not API.is_token_valid():
# print("-----------------------------") # print("-----------------------------")
# feed = API.run_job('post.listbyuserprofile', "simon-little") # feed = API.run_job('post.listbyuserprofile', "simon-little")
# print(feed) # print(feed)
print("-----------------------------") # print("-----------------------------")
post = API.run_job('post.create', { # post = API.run_job('post.create', {
# "blurLabel": None,
# "cardUrl": None,
# "postText": "This is a test post created via the API wrapper.",
# "collaborative": False,
# "parent": {
# "pk": "maintrunk#maintrunk",
# "sk": "maintrunk#maintrunk"
# }
# })
# print(post)
# print("-----------------------------")
post = API.run_job('comment.create', {
"blurLabel": None, "blurLabel": None,
"cardUrl": None, "commentText": "This is a test comment created via the API wrapper.",
"postText": "This is a test post created via the API wrapper.",
"collaborative": False,
"parent": { "parent": {
"pk": "maintrunk#maintrunk", "pk": "maintrunk#maintrunk",
"sk": "maintrunk#maintrunk" "sk": "post#1774951384-98fe38df",
} "slug": "1774951384-98fe38df"
},
"topLevel": {
"pk": "maintrunk#maintrunk",
"sk": "post#1774951384-98fe38df"
},
"version": 3
}) })
print(post) print(post)