40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
#!/usr/bin/python3
|
|
|
|
from lib.authentication import authenticate_mastodon
|
|
|
|
|
|
def setup_mastodon_data(config):
|
|
"""
|
|
Setup the config import and client
|
|
|
|
Returns:
|
|
obj -- Mastodon client object
|
|
"""
|
|
if(config['access_token'] and config['api_base_url']):
|
|
client = authenticate_mastodon(config)
|
|
else:
|
|
print('Mastodon API information missing/incomplete, skipping...')
|
|
return
|
|
return client
|
|
|
|
|
|
def mastodon_upload_media(config, media_files, body):
|
|
"""
|
|
Upload the archived media and original body text as a Mastodon status
|
|
|
|
Arguments:
|
|
media_files {str} -- Filenames for the uploaded media
|
|
body {str} -- String describing the original body text of the Tweet
|
|
"""
|
|
mastodon = setup_mastodon_data(config)
|
|
media_id_list = []
|
|
for media in media_files:
|
|
media_id_list.append(mastodon.media_post(
|
|
media_file=f'data/{media}', description='Sorry, this was a Twitter echo so there\'s no description :(', focus=(0, 0)))
|
|
try:
|
|
output = mastodon.status_post(
|
|
body, spoiler_text='Automated Twitter Repost', media_ids=media_id_list, visibility='public')
|
|
print(output)
|
|
except Exception as e:
|
|
print('There was some issue posting to Mastodon.')
|
|
print(e)
|