Skip to content

Commit fc7ba80

Browse files
committed
🪿 bump version
1 parent 52944dd commit fc7ba80

File tree

3 files changed

+87
-43
lines changed

3 files changed

+87
-43
lines changed

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-substack"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
description = "A Python wrapper around the Substack API."
55
authors = ["Paolo Mazza <mazzapaolo2019@gmail.com>"]
66
license = "MIT"
@@ -18,7 +18,7 @@ keywords = ["substack"]
1818
[tool.poetry.dependencies]
1919
python = "^3.7"
2020

21-
requests = "^2.28.1"
21+
requests = "^2.31.0"
2222
python-dotenv = "^0.21.0"
2323
PyYAML = "^6.0"
2424

‎substack/api.py‎

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class Api:
2121
"""
2222

2323
def __init__(
24-
self,
25-
email=None,
26-
password=None,
27-
base_url=None,
28-
publication_url=None,
29-
debug=False,
24+
self,
25+
email=None,
26+
password=None,
27+
base_url=None,
28+
publication_url=None,
29+
debug=False,
3030
):
3131
"""
3232
@@ -94,8 +94,10 @@ def _handle_response(response: requests.Response):
9494

9595
def get_publication_users(self):
9696
"""
97+
Get list of users.
98+
99+
Returns:
97100
98-
:return:
99101
"""
100102
response = self._session.get(f"{self.publication_url}/publication/users")
101103

@@ -104,20 +106,39 @@ def get_publication_users(self):
104106
def get_posts(self) -> dict:
105107
"""
106108
107-
:return:
109+
Returns:
110+
108111
"""
109112
response = self._session.get(f"{self.base_url}/reader/posts")
110113

111114
return Api._handle_response(response=response)
112115

113116
def get_drafts(self, filter=None, offset=None, limit=None):
117+
"""
118+
119+
Args:
120+
filter:
121+
offset:
122+
limit:
123+
124+
Returns:
125+
126+
"""
114127
response = self._session.get(
115128
f"{self.publication_url}/drafts",
116129
params={"filter": filter, "offset": offset, "limit": limit},
117130
)
118131
return Api._handle_response(response=response)
119132

120133
def delete_draft(self, draft_id):
134+
"""
135+
136+
Args:
137+
draft_id:
138+
139+
Returns:
140+
141+
"""
121142
response = self._session.delete(f"{self.publication_url}/drafts/{draft_id}")
122143
return Api._handle_response(response=response)
123144

@@ -134,12 +155,12 @@ def post_draft(self, body) -> dict:
134155
return Api._handle_response(response=response)
135156

136157
def put_draft(
137-
self,
138-
draft,
139-
title=None,
140-
subtitle=None,
141-
body=None,
142-
cover_image=None,
158+
self,
159+
draft,
160+
title=None,
161+
subtitle=None,
162+
body=None,
163+
cover_image=None,
143164
) -> dict:
144165
"""
145166
@@ -181,7 +202,7 @@ def prepublish_draft(self, draft) -> dict:
181202
return Api._handle_response(response=response)
182203

183204
def publish_draft(
184-
self, draft, send: bool = True, share_automatically: bool = False
205+
self, draft, send: bool = True, share_automatically: bool = False
185206
) -> dict:
186207
"""
187208
@@ -262,6 +283,16 @@ def get_categories(self):
262283
return Api._handle_response(response=response)
263284

264285
def get_category(self, category_id, category_type, page):
286+
"""
287+
288+
Args:
289+
category_id:
290+
category_type:
291+
page:
292+
293+
Returns:
294+
295+
"""
265296
response = self._session.get(
266297
f"{self.base_url}/category/public/{category_id}/{category_type}",
267298
params={"page": page},
@@ -289,7 +320,7 @@ def get_single_category(self, category_id, category_type, page=None, limit=None)
289320
page_output = self.get_category(category_id, category_type, page)
290321
publications.extend(page_output.get("publications", []))
291322
if (
292-
limit is not None and limit <= len(publications)
323+
limit is not None and limit <= len(publications)
293324
) or not page_output.get("more", False):
294325
publications = publications[:limit]
295326
break
@@ -301,6 +332,11 @@ def get_single_category(self, category_id, category_type, page=None, limit=None)
301332
return output
302333

303334
def delete_all_drafts(self):
335+
"""
336+
337+
Returns:
338+
339+
"""
304340
response = None
305341
while True:
306342
drafts = self.get_drafts(filter="draft", limit=10, offset=0)

‎substack/post.py‎

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
class Post:
88
def __init__(
9-
self,
10-
title: str,
11-
subtitle: str,
12-
user_id,
13-
audience: str = None,
14-
write_comment_permissions: str = None,
9+
self,
10+
title: str,
11+
subtitle: str,
12+
user_id,
13+
audience: str = None,
14+
write_comment_permissions: str = None,
1515
):
1616
"""
1717
@@ -121,20 +121,20 @@ def attrs(self, level):
121121
return self
122122

123123
def captioned_image(
124-
self,
125-
src: str,
126-
fullscreen: bool = False,
127-
imageSize: str = "normal",
128-
height: int = 819,
129-
width: int = 1456,
130-
resizeWidth: int = 728,
131-
bytes: str = None,
132-
alt: str = None,
133-
title: str = None,
134-
type: str = None,
135-
href: str = None,
136-
belowTheFold: bool = False,
137-
internalRedirect: str = None,
124+
self,
125+
src: str,
126+
fullscreen: bool = False,
127+
imageSize: str = "normal",
128+
height: int = 819,
129+
width: int = 1456,
130+
resizeWidth: int = 728,
131+
bytes: str = None,
132+
alt: str = None,
133+
title: str = None,
134+
type: str = None,
135+
href: str = None,
136+
belowTheFold: bool = False,
137+
internalRedirect: str = None,
138138
):
139139
"""
140140
@@ -243,15 +243,22 @@ def get_draft(self):
243243
out["draft_body"] = json.dumps(out["draft_body"])
244244
return out
245245

246-
def subscribe_with_caption(self, value: str):
246+
def subscribe_with_caption(self, message: str = None):
247247
"""
248248
249+
Add subscribe widget with caption
250+
249251
Args:
250-
value:
252+
message:
251253
252254
Returns:
253255
254256
"""
257+
258+
if message is None:
259+
message = """Thanks for reading this newsletter!
260+
Subscribe for free to receive new posts and support my work."""
261+
255262
content = self.draft_body["content"][-1].get("content", [])
256263
content += [
257264
{
@@ -263,8 +270,7 @@ def subscribe_with_caption(self, value: str):
263270
"content": [
264271
{
265272
"type": "text",
266-
"text": f"""Thanks for reading {value}!
267-
Subscribe for free to receive new posts and support my work.""",
273+
"text": message,
268274
}
269275
],
270276
}
@@ -277,8 +283,10 @@ def subscribe_with_caption(self, value: str):
277283
def youtube(self, value: str):
278284
"""
279285
286+
Add youtube video to post.
287+
280288
Args:
281-
value:
289+
value: youtube url
282290
283291
Returns:
284292

0 commit comments

Comments
 (0)