-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
240 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
|
||
from substack import Api | ||
|
||
load_dotenv() | ||
|
||
content = "" | ||
title = "" | ||
subtitle = "" | ||
|
||
api = Api( | ||
email=os.getenv("EMAIL"), | ||
password=os.getenv("PASSWORD"), | ||
publication_url=os.getenv("PUBLICATION_URL"), | ||
) | ||
|
||
body = f'{{"type":"doc","content": {content}}}' | ||
|
||
draft = api.post_draft( | ||
[{"id": os.getenv("USER_ID"), "is_guest": False}], | ||
title=title, | ||
subtitle=subtitle, | ||
body=body, | ||
) | ||
|
||
api.prepublish_draft(draft.get("id")) | ||
|
||
api.publish_draft(draft.get("id")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
"""A library that provides a Python interface to the Substack API.""" | ||
|
||
__author__ = 'Paolo Mazza' | ||
__email__ = '[email protected]' | ||
__license__ = 'MIT License' | ||
__version__ = '1.0' | ||
__url__ = 'https://github.com/hogier/python-substack' | ||
__download_url__ = 'https://pypi.python.org/pypi/python-substack' | ||
__description__ = 'A Python wrapper around the Substack API' | ||
__author__ = "Paolo Mazza" | ||
__email__ = "[email protected]" | ||
__license__ = "MIT License" | ||
__version__ = "1.0" | ||
__url__ = "https://github.com/hogier/python-substack" | ||
__download_url__ = "https://pypi.python.org/pypi/python-substack" | ||
__description__ = "A Python wrapper around the Substack API" | ||
|
||
from .api import Api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,64 @@ | ||
import os | ||
import unittest | ||
|
||
from dotenv import load_dotenv | ||
|
||
from substack import Api | ||
from substack.exceptions import SubstackAPIException | ||
|
||
load_dotenv() | ||
|
||
class ApiTest(unittest.TestCase): | ||
|
||
class ApiTest(unittest.TestCase): | ||
def test_api_exception(self): | ||
with self.assertRaises(SubstackAPIException): | ||
Api(email="", password="") | ||
|
||
def test_login(self): | ||
api = Api( | ||
email=os.getenv("EMAIL"), | ||
password=os.getenv("PASSWORD"), | ||
publication_url=os.getenv("PUBLICATION_URL"), | ||
) | ||
self.assertIsNotNone(api) | ||
|
||
def test_get_posts(self): | ||
api = Api(email=os.getenv("EMAIL"), password=os.getenv("PASSWORD")) | ||
posts = api.get_posts() | ||
self.assertIsNotNone(posts) | ||
|
||
def test_get_drafts(self): | ||
api = Api( | ||
email=os.getenv("EMAIL"), | ||
password=os.getenv("PASSWORD"), | ||
publication_url=os.getenv("PUBLICATION_URL"), | ||
) | ||
drafts = api.get_drafts() | ||
self.assertIsNotNone(drafts) | ||
|
||
def test_post_draft(self): | ||
api = Api( | ||
email=os.getenv("EMAIL"), | ||
password=os.getenv("PASSWORD"), | ||
publication_url=os.getenv("PUBLICATION_URL"), | ||
) | ||
posted_draft = api.post_draft([{"id": os.getenv("USER_ID"), "is_guest": False}]) | ||
self.assertIsNotNone(posted_draft) | ||
|
||
def test_publication_users(self): | ||
api = Api( | ||
email=os.getenv("EMAIL"), | ||
password=os.getenv("PASSWORD"), | ||
publication_url=os.getenv("PUBLICATION_URL"), | ||
) | ||
users = api.get_publication_users() | ||
self.assertIsNotNone(users) | ||
|
||
def test_put_draft(self): | ||
api = Api( | ||
email=os.getenv("EMAIL"), | ||
password=os.getenv("PASSWORD"), | ||
publication_url=os.getenv("PUBLICATION_URL"), | ||
) | ||
posted_draft = api.put_draft("62667935") | ||
self.assertIsNotNone(posted_draft) |