Skip to content

Commit

Permalink
🪿 bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2za committed Jun 12, 2023
1 parent 52944dd commit fc7ba80
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-substack"
version = "0.1.8"
version = "0.1.9"
description = "A Python wrapper around the Substack API."
authors = ["Paolo Mazza <mazzapaolo2019@gmail.com>"]
license = "MIT"
Expand All @@ -18,7 +18,7 @@ keywords = ["substack"]
[tool.poetry.dependencies]
python = "^3.7"

requests = "^2.28.1"
requests = "^2.31.0"
python-dotenv = "^0.21.0"
PyYAML = "^6.0"

Expand Down
68 changes: 52 additions & 16 deletions substack/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class Api:
"""

def __init__(
self,
email=None,
password=None,
base_url=None,
publication_url=None,
debug=False,
self,
email=None,
password=None,
base_url=None,
publication_url=None,
debug=False,
):
"""
Expand Down Expand Up @@ -94,8 +94,10 @@ def _handle_response(response: requests.Response):

def get_publication_users(self):
"""
Get list of users.
Returns:
:return:
"""
response = self._session.get(f"{self.publication_url}/publication/users")

Expand All @@ -104,20 +106,39 @@ def get_publication_users(self):
def get_posts(self) -> dict:
"""
:return:
Returns:
"""
response = self._session.get(f"{self.base_url}/reader/posts")

return Api._handle_response(response=response)

def get_drafts(self, filter=None, offset=None, limit=None):
"""
Args:
filter:
offset:
limit:
Returns:
"""
response = self._session.get(
f"{self.publication_url}/drafts",
params={"filter": filter, "offset": offset, "limit": limit},
)
return Api._handle_response(response=response)

def delete_draft(self, draft_id):
"""
Args:
draft_id:
Returns:
"""
response = self._session.delete(f"{self.publication_url}/drafts/{draft_id}")
return Api._handle_response(response=response)

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

def put_draft(
self,
draft,
title=None,
subtitle=None,
body=None,
cover_image=None,
self,
draft,
title=None,
subtitle=None,
body=None,
cover_image=None,
) -> dict:
"""
Expand Down Expand Up @@ -181,7 +202,7 @@ def prepublish_draft(self, draft) -> dict:
return Api._handle_response(response=response)

def publish_draft(
self, draft, send: bool = True, share_automatically: bool = False
self, draft, send: bool = True, share_automatically: bool = False
) -> dict:
"""
Expand Down Expand Up @@ -262,6 +283,16 @@ def get_categories(self):
return Api._handle_response(response=response)

def get_category(self, category_id, category_type, page):
"""
Args:
category_id:
category_type:
page:
Returns:
"""
response = self._session.get(
f"{self.base_url}/category/public/{category_id}/{category_type}",
params={"page": page},
Expand Down Expand Up @@ -289,7 +320,7 @@ def get_single_category(self, category_id, category_type, page=None, limit=None)
page_output = self.get_category(category_id, category_type, page)
publications.extend(page_output.get("publications", []))
if (
limit is not None and limit <= len(publications)
limit is not None and limit <= len(publications)
) or not page_output.get("more", False):
publications = publications[:limit]
break
Expand All @@ -301,6 +332,11 @@ def get_single_category(self, category_id, category_type, page=None, limit=None)
return output

def delete_all_drafts(self):
"""
Returns:
"""
response = None
while True:
drafts = self.get_drafts(filter="draft", limit=10, offset=0)
Expand Down
58 changes: 33 additions & 25 deletions substack/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class Post:
def __init__(
self,
title: str,
subtitle: str,
user_id,
audience: str = None,
write_comment_permissions: str = None,
self,
title: str,
subtitle: str,
user_id,
audience: str = None,
write_comment_permissions: str = None,
):
"""
Expand Down Expand Up @@ -121,20 +121,20 @@ def attrs(self, level):
return self

def captioned_image(
self,
src: str,
fullscreen: bool = False,
imageSize: str = "normal",
height: int = 819,
width: int = 1456,
resizeWidth: int = 728,
bytes: str = None,
alt: str = None,
title: str = None,
type: str = None,
href: str = None,
belowTheFold: bool = False,
internalRedirect: str = None,
self,
src: str,
fullscreen: bool = False,
imageSize: str = "normal",
height: int = 819,
width: int = 1456,
resizeWidth: int = 728,
bytes: str = None,
alt: str = None,
title: str = None,
type: str = None,
href: str = None,
belowTheFold: bool = False,
internalRedirect: str = None,
):
"""
Expand Down Expand Up @@ -243,15 +243,22 @@ def get_draft(self):
out["draft_body"] = json.dumps(out["draft_body"])
return out

def subscribe_with_caption(self, value: str):
def subscribe_with_caption(self, message: str = None):
"""
Add subscribe widget with caption
Args:
value:
message:
Returns:
"""

if message is 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 += [
{
Expand All @@ -263,8 +270,7 @@ def subscribe_with_caption(self, value: str):
"content": [
{
"type": "text",
"text": f"""Thanks for reading {value}!
Subscribe for free to receive new posts and support my work.""",
"text": message,
}
],
}
Expand All @@ -277,8 +283,10 @@ def subscribe_with_caption(self, value: str):
def youtube(self, value: str):
"""
Add youtube video to post.
Args:
value:
value: youtube url
Returns:
Expand Down

0 comments on commit fc7ba80

Please sign in to comment.