Skip to content

Commit d79f1ca

Browse files
committed
🏰 upkeep
1 parent 5708d5d commit d79f1ca

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ post.add({'type': 'captionedImage', 'src': "https://media.tenor.com/7B4jMa-a7bsA
9292
image = api.get_image('image.png')
9393
post.add({"type": "captionedImage", "src": image.get("url")})
9494

95+
# embed publication
96+
embedded = api.publication_embed("https://jackio.substack.com/")
97+
post.add({"type": "embeddedPublication", "url": embedded})
98+
9599
draft = api.post_draft(post.get_draft())
96100

97101
# set section (THIS CAN BE DONE ONLY AFTER HAVING FIRST POSTED THE DRAFT)

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.14"
3+
version = "0.1.15"
44
description = "A Python wrapper around the Substack API."
55
authors = ["Paolo Mazza <mazzapaolo2019@gmail.com>"]
66
license = "MIT"

substack/api.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ def signin_for_pub(self, publication):
128128
response = self._session.get(
129129
f"https://substack.com/sign-in?redirect=%2F&for_pub={publication['subdomain']}",
130130
)
131-
return Api._handle_response(response=response)
131+
try:
132+
output = Api._handle_response(response=response)
133+
except SubstackRequestException as ex:
134+
output = {}
135+
return output
132136

133137
def change_publication(self, publication):
134138
"""
@@ -538,3 +542,32 @@ def get_sections(self):
538542
if p.get("hostname") in self.publication_url
539543
]
540544
return sections[0]
545+
546+
def publication_embed(self, url):
547+
"""
548+
549+
Args:
550+
url:
551+
552+
Returns:
553+
554+
"""
555+
return self.call("/publication/embed", "GET", url=url)
556+
557+
def call(self, endpoint, method, **params):
558+
"""
559+
560+
Args:
561+
endpoint:
562+
method:
563+
**params:
564+
565+
Returns:
566+
567+
"""
568+
response = self._session.request(
569+
method=method,
570+
url=f"{self.publication_url}/{endpoint}",
571+
params=params,
572+
)
573+
return Api._handle_response(response=response)

substack/post.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def add(self, item: Dict):
8484
content = item.get("content")
8585
if item.get("type") == "captionedImage":
8686
self.captioned_image(**item)
87+
elif item.get("type") == "embeddedPublication":
88+
self.draft_body["content"][-1]["attrs"] = item.get("url")
8789
elif item.get("type") == "youtube2":
8890
self.youtube(item.get("src"))
8991
elif item.get("type") == "subscribeWidget":

0 commit comments

Comments
 (0)