Minor refactor related to init callbacks
This commit is contained in:
parent
35a303caa8
commit
6066e872aa
@ -26,9 +26,11 @@ class FailedLogin(Exception):
|
|||||||
|
|
||||||
class FediStatusPoster:
|
class FediStatusPoster:
|
||||||
def __init__(self, client_id, client_secret, access_token, api_base_url, feature_set="pleroma", debug_mode=False):
|
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.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):
|
def login(self, client_id, client_secret, access_token, api_base_url, feature_set):
|
||||||
try:
|
try:
|
||||||
@ -48,18 +50,16 @@ class FediStatusPoster:
|
|||||||
if path is None or not os.path.isfile(path):
|
if path is None or not os.path.isfile(path):
|
||||||
raise FileNotFoundError("Not a File: {}".format(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}
|
return {"url": path, "description": description}
|
||||||
|
|
||||||
def upload_media_list(self, path_list):
|
def upload_media_list(self, path_list):
|
||||||
self.validate_media_list(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 = []
|
media_list = []
|
||||||
for path in path_list:
|
for path in path_list:
|
||||||
description = os.path.basename(path)
|
description = os.path.basename(path)
|
||||||
media = callback(path, description=description)
|
media = self.media_post(path, description=description)
|
||||||
media_dict = {
|
media_dict = {
|
||||||
"path": path,
|
"path": path,
|
||||||
"media": media
|
"media": media
|
||||||
|
Loading…
Reference in New Issue
Block a user