Compare commits

..

2 Commits

Author SHA1 Message Date
6066e872aa Minor refactor related to init callbacks 2024-07-17 00:04:56 -07:00
35a303caa8 Minor refactor for arg parsing. 2024-07-16 23:35:10 -07:00

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
@ -170,10 +170,10 @@ def main():
arguments = parser.parse_args()
# Session Token Variables
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")
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")
# Flag if the bot is running in debug mode
debug_mode = arguments.dry_run or arguments.debug