Compare commits
No commits in common. "6066e872aa7762cd3b8456ca80955fd47a344baf" and "79973b7f114d88991e32dfda8ae66f6c50542d1b" have entirely different histories.
6066e872aa
...
79973b7f11
@ -26,11 +26,9 @@ class FailedLogin(Exception):
|
||||
|
||||
class FediStatusPoster:
|
||||
def __init__(self, client_id, client_secret, access_token, api_base_url, feature_set="pleroma", debug_mode=False):
|
||||
self.debug_mode = debug_mode
|
||||
self.mastodon_api = self.login(client_id, client_secret, access_token, api_base_url, feature_set)
|
||||
|
||||
# Callback functions
|
||||
self.status_post = self._status_post_debug if debug_mode else self._status_post
|
||||
self.media_post = self._media_post_debug if debug_mode else self.mastodon_api.media_post
|
||||
self.status_post = self._status_post if not self.debug_mode else self._status_post_debug
|
||||
|
||||
def login(self, client_id, client_secret, access_token, api_base_url, feature_set):
|
||||
try:
|
||||
@ -50,16 +48,18 @@ class FediStatusPoster:
|
||||
if path is None or not os.path.isfile(path):
|
||||
raise FileNotFoundError("Not a File: {}".format(path))
|
||||
|
||||
def _media_post_debug(self, path, description):
|
||||
def media_post_debug(self, path, description):
|
||||
return {"url": path, "description": description}
|
||||
|
||||
def upload_media_list(self, path_list):
|
||||
self.validate_media_list(path_list)
|
||||
|
||||
callback = self.mastodon_api.media_post if not self.debug_mode else self.media_post_debug
|
||||
|
||||
media_list = []
|
||||
for path in path_list:
|
||||
description = os.path.basename(path)
|
||||
media = self.media_post(path, description=description)
|
||||
media = callback(path, description=description)
|
||||
media_dict = {
|
||||
"path": path,
|
||||
"media": media
|
||||
@ -170,10 +170,10 @@ def main():
|
||||
arguments = parser.parse_args()
|
||||
|
||||
# Session Token Variables
|
||||
api_base_url = arguments.api_base_url or os.environ.get("API_BASE_URL")
|
||||
client_id = arguments.client_id or os.environ.get("CLIENT_ID")
|
||||
client_secret = arguments.client_secret or os.environ.get("CLIENT_SECRET")
|
||||
access_token = arguments.access_token or os.environ.get("ACCESS_TOKEN")
|
||||
api_base_url = arguments.api_base_url if arguments.api_base_url else os.environ.get("API_BASE_URL")
|
||||
client_id = arguments.client_id if arguments.client_id else os.environ.get("CLIENT_ID")
|
||||
client_secret = arguments.client_secret if arguments.client_secret else os.environ.get("CLIENT_SECRET")
|
||||
access_token = arguments.access_token if arguments.access_token else os.environ.get("ACCESS_TOKEN")
|
||||
|
||||
# Flag if the bot is running in debug mode
|
||||
debug_mode = arguments.dry_run or arguments.debug
|
||||
|
Loading…
Reference in New Issue
Block a user