social-photos/publish_pixelfed.py

23 lines
932 B
Python
Raw Normal View History

import load_config
from mastodon import Mastodon
2023-11-05 19:20:03 +00:00
m = Mastodon(access_token=load_config.config['pixelfed']['token'], api_base_url="https://pixelfed.scot")
2023-11-05 19:20:03 +00:00
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'])
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']}\n{tag_string}"
def formatTags(tags: list):
formatted_tags = ['#' + tag.title().replace(' ', '') for tag in tags]
formatted_tags_str = ' '.join(formatted_tags)
return formatted_tags_str