diff --git a/README.md b/README.md index a4332fd..fe756b5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/draft.yaml b/examples/draft.yaml index e49f9ff..a969ada 100644 --- a/examples/draft.yaml +++ b/examples/draft.yaml @@ -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" @@ -30,4 +33,10 @@ body: content: "Set the EMAIL, PASSWORD, PUBLICATION_URL and USER_ID environment variables." 7: type: "captionedImage" - src: "rickroll_4k.jpg" \ No newline at end of file + src: "rickroll_4k.jpg" + 8: + type: "youtube2" + src: "EnDg65ISswg" + 9: + type: "subscribeWidget" + message: "Hello Everyone!!!" \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index 59c277c..416ea43 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,9 +1,10 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "certifi" version = "2023.7.22" description = "Python package for providing Mozilla's CA Bundle." +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -15,6 +16,7 @@ files = [ name = "charset-normalizer" version = "3.1.0" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -99,6 +101,7 @@ files = [ name = "idna" version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" optional = false python-versions = ">=3.5" files = [ @@ -110,6 +113,7 @@ files = [ name = "python-dotenv" version = "0.21.1" description = "Read key-value pairs from a .env file and set them as environment variables" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -124,6 +128,7 @@ cli = ["click (>=5.0)"] name = "pyyaml" version = "6.0" description = "YAML parser and emitter for Python" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -173,6 +178,7 @@ files = [ name = "requests" version = "2.31.0" description = "Python HTTP for Humans." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -194,6 +200,7 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] name = "urllib3" version = "2.0.6" description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" optional = false python-versions = ">=3.7" files = [ diff --git a/pyproject.toml b/pyproject.toml index e51b1a0..31ee88d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT" diff --git a/substack/post.py b/substack/post.py index 0318d2c..abf956b 100644 --- a/substack/post.py +++ b/substack/post.py @@ -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) @@ -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):