Skip to content

Commit 1979fff

Browse files
committed
feat: enhance draft publishing with additional metadata and update version to 0.1.20
1 parent 88cf3b5 commit 1979fff

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ for _, item in body.items():
212212
post.add(item)
213213

214214
draft = api.post_draft(post.get_draft())
215-
api.put_draft(draft.get("id"), draft_section_id=post.draft_section_id)
215+
put_draft_kwargs = {
216+
"draft_section_id": post.draft_section_id,
217+
"search_engine_title": post_data.get("search_engine_title"),
218+
"search_engine_description": post_data.get("search_engine_description"),
219+
"slug": post_data.get("slug"),
220+
}
221+
put_draft_kwargs = {k: v for k, v in put_draft_kwargs.items() if v is not None}
222+
api.put_draft(draft.get("id"), **put_draft_kwargs)
216223

217224
# Publish the draft
218225
api.prepublish_draft(draft.get("id"))

examples/draft.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ audience:
66
"everyone" # everyone, only_paid, founding, only_free
77
write_comment_permissions:
88
"none" # none, only_paid, everyone
9+
search_engine_title:
10+
"This is a short SEO title set via the Python API wrapper."
11+
search_engine_description:
12+
"This is a short SEO description set via the Python API wrapper."
13+
slug:
14+
"this-is-a-draft-post-2"
915
section:
1016
"rick"
1117
tags:

examples/publish_post.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
type=str,
2121
)
2222
parser.add_argument(
23-
"--publish", help="Publish the draft.", action="store_true", default=True
23+
"--publish", help="Publish the draft.", action="store_false", default=False
2424
)
2525
parser.add_argument(
2626
"--cookies",
@@ -38,7 +38,9 @@
3838

3939
api = Api(
4040
email=os.getenv("EMAIL") if not cookies_path and not cookies_string else None,
41-
password=os.getenv("PASSWORD") if not cookies_path and not cookies_string else None,
41+
password=os.getenv("PASSWORD")
42+
if not cookies_path and not cookies_string
43+
else None,
4244
cookies_path=cookies_path,
4345
cookies_string=cookies_string,
4446
publication_url=os.getenv("PUBLICATION_URL"),
@@ -67,7 +69,16 @@
6769
draft = api.post_draft(post.get_draft())
6870

6971
# post.set_section(post_data.get("section"), api.get_sections())
70-
api.put_draft(draft.get("id"), draft_section_id=post.draft_section_id)
72+
put_draft_kwargs = {
73+
"draft_section_id": post.draft_section_id,
74+
"search_engine_title": post_data.get("search_engine_title"),
75+
"search_engine_description": post_data.get("search_engine_description"),
76+
"slug": post_data.get("slug"),
77+
}
78+
# Remove None values so we only send fields that were explicitly provided
79+
put_draft_kwargs = {k: v for k, v in put_draft_kwargs.items() if v is not None}
80+
81+
api.put_draft(draft.get("id"), **put_draft_kwargs)
7182

7283
api.add_tags_to_post(draft.get("id"), post_data.get("tags", []))
7384

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-substack"
3-
version = "0.1.19"
3+
version = "0.1.20"
44
description = "A Python wrapper around the Substack API."
55
authors = ["Paolo Mazza <mazzapaolo2019@gmail.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)