So far I've been able to get posts to create, but not update. Since a semi-recent update to their backend, I've had to monkeypatch the create_post
piazza api seen below for working example:
# login to piazza with a specific class
# all class specifics should be given either
# in an .env file (development) or environment
# variables
piazza_access = Piazza()
piazza_access.user_login(
email=login_credentials.email,
password=login_credentials.password.get_secret_value(),
)
# login to that specific course.
course_logged = piazza_access.network(network_id=login_credentials.course_id)
def create_post(
self,
post_type,
post_folders,
post_subject,
post_content,
visible_to,
is_announcement=0,
bypass_email=0,
anonymous=False,
):
"""Create a post
It seems like if the post has `<p>` tags, then it's treated as HTML,
but is treated as text otherwise. You'll want to provide `content`
accordingly.
:type post_type: str
:param post_type: 'note', 'question'
:type post_folders: str
:param post_folders: Folder to put post into
:type post_subject: str
:param post_subject: Subject string
:type post_content: str
:param post_content: Content string
:type visible_to: str
:param visible_to: Users this post is visible to
:type is_announcement: bool
:param is_announcement:
:type bypass_email: bool
:param bypass_email:
:type anonymous: bool
:param anonymous:
:rtype: dict
:returns: Dictionary with information about the created post.
"""
params = {
"anonymous": "yes" if anonymous else "no",
"subject": post_subject,
"content": post_content,
"folders": post_folders,
"type": post_type,
"config": {
"bypass_email": bypass_email,
"is_announcement": is_announcement,
"feed_groups": visible_to,
},
}
return self._rpc.content_create(params)
course.create_post = types.MethodType(monkeypatch.create_post, course)
#### This works just fine!!!
course.create_post(
**CreatePostModel( # pydantic model with needed info
post_type="note",
post_folders=["other"],
visible_to=posted_to,
post_content=lecture_content_html,
post_subject="Lecture Slides",
).model_dump()
However, no luck for updating posts, anything similar like feeding in cid (post id) and post content, and any permutation of the additional info needed for the create monkeypatch, gives the same response:
def update_post_monkeypatch(
self,
cid: int,
post_type: str,
post_folders: str,
post_subject: str,
post_content: str,
visible_to: str,
is_announcement: int = 0,
bypass_email: int = 1,
anonymous: bool = False,
):
"""Update a post, the **updated** way!
It seems like if the post has `<p>` tags, then it's treated as HTML,
but is treated as text otherwise. You'll want to provide `content`
accordingly.
:type post_type: str
:param post_type: 'note', 'question'
:type post_folders: str
:param post_folders: Folder to put post into
:type post_subject: str
:param post_subject: Subject string
:type post_content: str
:param post_content: Content string
:type visible_to: str
:param visible_to: Users this post is visible to
:type is_announcement: bool
:param is_announcement:
:type bypass_email: bool
:param bypass_email:
:type anonymous: bool
:param anonymous:
:rtype: dict
:returns: Dictionary with information about the created post.
"""
# Tried any permutation starting with simplest (cid and content) and iterated, but no luck
params = {
"cid": cid,
"anonymous": "yes" if anonymous else "no",
"subject": post_subject,
"content": post_content,
"folders": post_folders,
"type": post_type,
"config": {
"bypass_email": bypass_email,
"is_announcement": is_announcement,
"feed_groups": visible_to,
},
}
return self._rpc.content_update(params)
course.update_post = types.MethodType(update_post_monkeypatch, course)
course.update_post(
**UpdatePostModel(
cid=post_id,
post_type="note",
post_folders=["other"],
# visible_to=posted_to,
post_content=lecture_content_html,
post_subject="Lecture Slides",
).model_dump()
)
Something to do with this url made to piazza's backend: https://piazza.com/logic/api?method=content.update&aid=<aid-nonce_here>
Response: {\n "result": null,\n "error_codes": [],\n "error": "The post you are looking for cannot be found",\n "aid": "luxl22pj6p74en"\n}
I've tried every permutation or including or excluding things, and haven't been able to make any headway, so I'm a bit stumped! Any ideas? Happy to do some work on this if someone knows a fix.