Skip to content

Commit 7c60d8d

Browse files
committed
🦧 support for local images
1 parent d263c53 commit 7c60d8d

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎examples/draft.yaml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ body:
1919
type: "paragraph"
2020
content: "2)"
2121
5:
22+
type: "captionedImage"
23+
src: "https://media.tenor.com/7B4jMa-a7bsAAAAC/i-am-batman.gif"
24+
6:
2225
type: "paragraph"
2326
content: "Set the EMAIL, PASSWORD, PUBLICATION_URL and USER_ID environment variables."
24-
6:
27+
7:
2528
type: "captionedImage"
26-
src: "https://i.insider.com/602ee9d81a89f20019a377c6?width=1136&format=jpeg"
29+
src: "rickroll_4k.jpg"

‎examples/rickroll_4k.jpg‎

105 KB
Loading

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

‎substack/api.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import base64
12
import logging
3+
import os
24
from datetime import datetime
35
from urllib.parse import urljoin
46

@@ -234,14 +236,18 @@ def get_image(self, image: str):
234236
This method generates a new substack link that contains the image.
235237
236238
Args:
237-
image: original url to image.
239+
image: filepath or original url of image.
238240
239241
Returns:
240242
241243
"""
244+
if os.path.exists(image):
245+
with open(image, "rb") as file:
246+
image = b"data:image/jpeg;base64," + base64.b64encode(file.read())
247+
242248
response = self._session.post(
243249
f"{self.publication_url}/image",
244-
json={
250+
data={
245251
"image": image
246252
},
247253
)

0 commit comments

Comments
 (0)