Complete Pixelfed/Mastodon publishing

This commit is contained in:
Fred Boniface 2023-11-05 19:20:03 +00:00
parent 41f0a5c31f
commit 0b7d7fe58e
4 changed files with 21 additions and 5 deletions

View File

@ -44,6 +44,7 @@ def main():
if load_config.config['pixelfed']['enable']:
print("Pixelfed publishing enabled")
import publish_pixelfed
publish_pixelfed.upload(file_data)
def list_files_in_directory(directory):
top_level_items = os.listdir(directory)

View File

@ -10,7 +10,7 @@ def upload(file_data: list):
flickr.upload(
filename = file['path'],
title = file['title'],
description = file['description'],
description = file['description'] + load_config.config['flickr']['add_to_description'],
tags = prepareTags(file['tags']),
is_public = 1,
format = 'rest'

View File

@ -2,7 +2,22 @@ import load_config
from mastodon import Mastodon
Mastodon.create_app("social_photos", api_base_url=load_config.config['pixelfed']['server'], user_agent="social-photos")
Mastodon.log_in(code=load_config['pixelfed']['token'])
m = Mastodon(access_token=load_config.config['pixelfed']['token'], api_base_url="https://pixelfed.scot")
mastodon = Mastodon(access_token = 'pytooter_usercred.secret')
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