import load_config
from mastodon import Mastodon
m = Mastodon(access_token=load_config.config['pixelfed']['token'], api_base_url=load_config.config['pixelfed']['server'])
def upload(file_data: list):
for file in file_data:
print("Uploading image to Pixelfed")
media_upload = m.media_post(file['path'], "image/jpeg")
print("Posting to Pixelfed")
post_upload = m.status_post(formatPost(file), media_ids = media_upload['id'], visibility="public")
return post_upload['url']
def formatPost(file: dict):
tag_string = formatTags(file['tags'])
if load_config.config['pixelfed']['add_to_description']:
file['description'] = file['description'] + load_config.config['pixelfed']['add_to_description']
return f"{file['title']} | {file['description']}
{tag_string}" # Date needs adding
def formatTags(tags: list):
formatted_tags = ['#' + tag.title().replace(' ', '') for tag in tags]
formatted_tags_str = ' '.join(formatted_tags)
return formatted_tags_str