107 lines
3.2 KiB
Python
107 lines
3.2 KiB
Python
#!/usr/bin/python3
|
|
|
|
from lib.setup import import_config_file
|
|
from lib.authentication import authenticate_mastodon
|
|
#from mastodon import Mastodon as masto
|
|
# from sys import argv
|
|
# from os.path import expanduser
|
|
|
|
|
|
def setup_mastodon_data():
|
|
config = import_config_file()
|
|
if(config['mastodon']['access_token'] and config['mastodon']['api_base_url']):
|
|
client = authenticate_mastodon(config)
|
|
else:
|
|
print('Mastodon API information missing/incomplete, skipping...')
|
|
return
|
|
return client
|
|
|
|
|
|
def mastodon_upload_media(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()
|
|
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)
|
|
|
|
|
|
|
|
# def strip_quotes(input):
|
|
# """
|
|
# Strip quotes from input arguments
|
|
|
|
# Arguments:
|
|
# input {str} -- Input string that has quotes needing to be stripped or checked to be stripped
|
|
|
|
# Returns:
|
|
# str -- Resulting string
|
|
# """
|
|
# if(input[0] == '\"' and input[len(input) - 1] == '\"'):
|
|
# return input[1:len(input) - 1]
|
|
# else:
|
|
# return input
|
|
|
|
|
|
# def make_post(mastodon, body, cw=''):
|
|
# """
|
|
# Post to Mastodon, using the initialized Mastodon.py object
|
|
|
|
# Arguments:
|
|
# mastodon {obj} -- Mastodon client object
|
|
# body {str} -- String describing the body of the message
|
|
|
|
# Keyword Arguments:
|
|
# cw {str} -- String describing the content warning of the message (default: {''})
|
|
# """
|
|
# try:
|
|
# output = ''
|
|
# if(cw):
|
|
# output = mastodon.status_post(status=body, spoiler_text=cw)
|
|
# else:
|
|
# output = mastodon.toot(body)
|
|
# print("Posted successfully.\nContent Warning: {0}\nContent: {1}\nCreated at: {2}\nURL: {3}".format(
|
|
# output['spoiler_text'], output['content'], output['created_at'], output['url']))
|
|
# except Exception as e:
|
|
# print(str(e))
|
|
# print('There was an issue.')
|
|
|
|
# def main():
|
|
# """
|
|
# Main function that causes the script to post.
|
|
# """
|
|
|
|
# # Authorize Mastodon, set api base
|
|
# # TODO: Modularize this
|
|
# mastodon = masto(
|
|
# access_token='/home/shadow8t4/scripts/python/post-mastodon/.secrets/mastodon_api_access_token.secret',
|
|
# api_base_url='https://masto.werefox.dev'
|
|
# )
|
|
|
|
# cw = ''
|
|
# body = ''
|
|
|
|
# if(len(argv) > 2):
|
|
# cw = strip_quotes(argv[1])
|
|
# body = strip_quotes(argv[2])
|
|
# else:
|
|
# body = strip_quotes(argv[1])
|
|
|
|
# make_post(mastodon, body, cw)
|
|
|
|
|
|
# if(__name__ == '__main__'):
|
|
# main()
|