Compare commits

..

No commits in common. "6066e872aa7762cd3b8456ca80955fd47a344baf" and "79973b7f114d88991e32dfda8ae66f6c50542d1b" have entirely different histories.

View File

@ -26,11 +26,9 @@ 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:
@ -50,16 +48,18 @@ 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 = self.media_post(path, description=description) media = callback(path, description=description)
media_dict = { media_dict = {
"path": path, "path": path,
"media": media "media": media
@ -170,10 +170,10 @@ def main():
arguments = parser.parse_args() arguments = parser.parse_args()
# Session Token Variables # Session Token Variables
api_base_url = arguments.api_base_url or os.environ.get("API_BASE_URL") api_base_url = arguments.api_base_url if arguments.api_base_url else os.environ.get("API_BASE_URL")
client_id = arguments.client_id or os.environ.get("CLIENT_ID") client_id = arguments.client_id if arguments.client_id else os.environ.get("CLIENT_ID")
client_secret = arguments.client_secret or os.environ.get("CLIENT_SECRET") client_secret = arguments.client_secret if arguments.client_secret else os.environ.get("CLIENT_SECRET")
access_token = arguments.access_token or os.environ.get("ACCESS_TOKEN") access_token = arguments.access_token if arguments.access_token else os.environ.get("ACCESS_TOKEN")
# Flag if the bot is running in debug mode # Flag if the bot is running in debug mode
debug_mode = arguments.dry_run or arguments.debug debug_mode = arguments.dry_run or arguments.debug