Minor refactor related to init callbacks

This commit is contained in:
Anon 2024-07-17 00:04:56 -07:00
parent 35a303caa8
commit 6066e872aa

View File

@ -26,9 +26,11 @@ 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)
self.status_post = self._status_post if not self.debug_mode else self._status_post_debug
# 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
def login(self, client_id, client_secret, access_token, api_base_url, feature_set):
try:
@ -48,18 +50,16 @@ 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 = callback(path, description=description)
media = self.media_post(path, description=description)
media_dict = {
"path": path,
"media": media