Skip to content

Commit d827294

Browse files
committed
🏰 upkeep
1 parent 87163e3 commit d827294

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ The .env file will be ignored by git but always be careful.
3636

3737
# Usage
3838

39+
Check out the examples folder for some examples 😃 🚀
40+
41+
## Add a YouTube video
42+
3943
```python
4044
import os
4145

examples/draft.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ body:
1414
1:
1515
type: "paragraph"
1616
content: "1)"
17+
marks:
18+
- type: "strong"
19+
- type: "em"
1720
2:
1821
type: "paragraph"
1922
content: "discover the USER_ID in the url of the public profile page"
@@ -30,4 +33,10 @@ body:
3033
content: "Set the EMAIL, PASSWORD, PUBLICATION_URL and USER_ID environment variables."
3134
7:
3235
type: "captionedImage"
33-
src: "rickroll_4k.jpg"
36+
src: "rickroll_4k.jpg"
37+
8:
38+
type: "youtube2"
39+
src: "EnDg65ISswg"
40+
9:
41+
type: "subscribeWidget"
42+
message: "Hello Everyone!!!"

poetry.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

substack/post.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def add(self, item: Dict):
5454
self.captioned_image(**item)
5555
elif item.get("type") == "youtube2":
5656
self.youtube(item.get("src"))
57+
elif item.get("type") == "subscribeWidget":
58+
self.subscribe_with_caption(item.get("message"))
5759
else:
5860
if content is not None:
5961
self.add_complex_text(content)
@@ -259,25 +261,19 @@ def subscribe_with_caption(self, message: str = None):
259261
message = """Thanks for reading this newsletter!
260262
Subscribe for free to receive new posts and support my work."""
261263

262-
content = self.draft_body["content"][-1].get("content", [])
263-
content += [
264+
subscribe = self.draft_body["content"][-1]
265+
subscribe["attrs"] = {"url": "%%checkout_url%%", "text": "Subscribe", "language": "en"}
266+
subscribe["content"] = [
264267
{
265-
"type": "subscribeWidget",
266-
"attrs": {"url": "%%checkout_url%%", "text": "Subscribe"},
268+
"type": "ctaCaption",
267269
"content": [
268270
{
269-
"type": "ctaCaption",
270-
"content": [
271-
{
272-
"type": "text",
273-
"text": message,
274-
}
275-
],
271+
"type": "text",
272+
"text": message,
276273
}
277274
],
278275
}
279276
]
280-
self.draft_body["content"][-1]["content"] = content
281277
return self
282278

283279
def youtube(self, value: str):

0 commit comments

Comments
 (0)