Complete Pixelfed/Mastodon publishing
This commit is contained in:
parent
41f0a5c31f
commit
0b7d7fe58e
1
main.py
1
main.py
@ -44,6 +44,7 @@ def main():
|
|||||||
if load_config.config['pixelfed']['enable']:
|
if load_config.config['pixelfed']['enable']:
|
||||||
print("Pixelfed publishing enabled")
|
print("Pixelfed publishing enabled")
|
||||||
import publish_pixelfed
|
import publish_pixelfed
|
||||||
|
publish_pixelfed.upload(file_data)
|
||||||
|
|
||||||
def list_files_in_directory(directory):
|
def list_files_in_directory(directory):
|
||||||
top_level_items = os.listdir(directory)
|
top_level_items = os.listdir(directory)
|
||||||
|
@ -10,7 +10,7 @@ def upload(file_data: list):
|
|||||||
flickr.upload(
|
flickr.upload(
|
||||||
filename = file['path'],
|
filename = file['path'],
|
||||||
title = file['title'],
|
title = file['title'],
|
||||||
description = file['description'],
|
description = file['description'] + load_config.config['flickr']['add_to_description'],
|
||||||
tags = prepareTags(file['tags']),
|
tags = prepareTags(file['tags']),
|
||||||
is_public = 1,
|
is_public = 1,
|
||||||
format = 'rest'
|
format = 'rest'
|
||||||
|
@ -2,7 +2,22 @@ import load_config
|
|||||||
|
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
|
|
||||||
Mastodon.create_app("social_photos", api_base_url=load_config.config['pixelfed']['server'], user_agent="social-photos")
|
m = Mastodon(access_token=load_config.config['pixelfed']['token'], api_base_url="https://pixelfed.scot")
|
||||||
Mastodon.log_in(code=load_config['pixelfed']['token'])
|
|
||||||
|
|
||||||
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
|
Loading…
Reference in New Issue
Block a user