Skip to content

Commit

Permalink
🏰 upkeep
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2za committed Dec 26, 2023
1 parent 5708d5d commit d79f1ca
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ post.add({'type': 'captionedImage', 'src': "https://media.tenor.com/7B4jMa-a7bsA
image = api.get_image('image.png')
post.add({"type": "captionedImage", "src": image.get("url")})

# embed publication
embedded = api.publication_embed("https://jackio.substack.com/")
post.add({"type": "embeddedPublication", "url": embedded})

draft = api.post_draft(post.get_draft())

# set section (THIS CAN BE DONE ONLY AFTER HAVING FIRST POSTED THE DRAFT)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-substack"
version = "0.1.14"
version = "0.1.15"
description = "A Python wrapper around the Substack API."
authors = ["Paolo Mazza <[email protected]>"]
license = "MIT"
Expand Down
35 changes: 34 additions & 1 deletion substack/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ def signin_for_pub(self, publication):
response = self._session.get(
f"https://substack.com/sign-in?redirect=%2F&for_pub={publication['subdomain']}",
)
return Api._handle_response(response=response)
try:
output = Api._handle_response(response=response)
except SubstackRequestException as ex:
output = {}
return output

def change_publication(self, publication):
"""
Expand Down Expand Up @@ -538,3 +542,32 @@ def get_sections(self):
if p.get("hostname") in self.publication_url
]
return sections[0]

def publication_embed(self, url):
"""
Args:
url:
Returns:
"""
return self.call("/publication/embed", "GET", url=url)

def call(self, endpoint, method, **params):
"""
Args:
endpoint:
method:
**params:
Returns:
"""
response = self._session.request(
method=method,
url=f"{self.publication_url}/{endpoint}",
params=params,
)
return Api._handle_response(response=response)
2 changes: 2 additions & 0 deletions substack/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def add(self, item: Dict):
content = item.get("content")
if item.get("type") == "captionedImage":
self.captioned_image(**item)
elif item.get("type") == "embeddedPublication":
self.draft_body["content"][-1]["attrs"] = item.get("url")
elif item.get("type") == "youtube2":
self.youtube(item.get("src"))
elif item.get("type") == "subscribeWidget":
Expand Down

0 comments on commit d79f1ca

Please sign in to comment.