Skip to content

Commit

Permalink
🏰 upkeep
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2za committed Oct 17, 2023
1 parent 87163e3 commit d827294
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ The .env file will be ignored by git but always be careful.

# Usage

Check out the examples folder for some examples 😃 🚀

## Add a YouTube video

```python
import os

Expand Down
11 changes: 10 additions & 1 deletion examples/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ body:
1:
type: "paragraph"
content: "1)"
marks:
- type: "strong"
- type: "em"
2:
type: "paragraph"
content: "discover the USER_ID in the url of the public profile page"
Expand All @@ -30,4 +33,10 @@ body:
content: "Set the EMAIL, PASSWORD, PUBLICATION_URL and USER_ID environment variables."
7:
type: "captionedImage"
src: "rickroll_4k.jpg"
src: "rickroll_4k.jpg"
8:
type: "youtube2"
src: "EnDg65ISswg"
9:
type: "subscribeWidget"
message: "Hello Everyone!!!"
9 changes: 8 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.9"
version = "0.1.10"
description = "A Python wrapper around the Substack API."
authors = ["Paolo Mazza <[email protected]>"]
license = "MIT"
Expand Down
20 changes: 8 additions & 12 deletions substack/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def add(self, item: Dict):
self.captioned_image(**item)
elif item.get("type") == "youtube2":
self.youtube(item.get("src"))
elif item.get("type") == "subscribeWidget":
self.subscribe_with_caption(item.get("message"))
else:
if content is not None:
self.add_complex_text(content)
Expand Down Expand Up @@ -259,25 +261,19 @@ def subscribe_with_caption(self, message: str = None):
message = """Thanks for reading this newsletter!
Subscribe for free to receive new posts and support my work."""

content = self.draft_body["content"][-1].get("content", [])
content += [
subscribe = self.draft_body["content"][-1]
subscribe["attrs"] = {"url": "%%checkout_url%%", "text": "Subscribe", "language": "en"}
subscribe["content"] = [
{
"type": "subscribeWidget",
"attrs": {"url": "%%checkout_url%%", "text": "Subscribe"},
"type": "ctaCaption",
"content": [
{
"type": "ctaCaption",
"content": [
{
"type": "text",
"text": message,
}
],
"type": "text",
"text": message,
}
],
}
]
self.draft_body["content"][-1]["content"] = content
return self

def youtube(self, value: str):
Expand Down

0 comments on commit d827294

Please sign in to comment.