2023-11-05 14:22:32 +00:00
|
|
|
import load_config
|
|
|
|
import image_processing
|
|
|
|
|
2023-11-05 23:58:53 +00:00
|
|
|
import os, sys, time
|
2023-11-05 14:22:32 +00:00
|
|
|
|
2023-11-05 19:23:31 +00:00
|
|
|
####
|
|
|
|
# CURRENT ISSUES
|
|
|
|
####
|
|
|
|
#
|
2023-11-05 19:26:47 +00:00
|
|
|
# Pixelfed API doesn't honour newlines. - Possibly look at HTML formatting?
|
|
|
|
# Pixelfed publishing is missing date - Needs parsing and appending to description
|
2023-11-05 19:23:31 +00:00
|
|
|
|
|
|
|
|
2023-11-05 14:22:32 +00:00
|
|
|
def main():
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("Usage: social-photos <directory_or_file_path>")
|
|
|
|
else:
|
|
|
|
path = sys.argv[1]
|
|
|
|
|
|
|
|
if not os.path.exists(path):
|
|
|
|
print(f"'{path}' does not exist.")
|
|
|
|
sys.exit(1)
|
|
|
|
elif os.path.isfile(path):
|
|
|
|
print(f"'{path}' is a file.")
|
|
|
|
files = [path]
|
|
|
|
elif os.path.isdir(path):
|
|
|
|
print(f"'{path}' is a directory.")
|
|
|
|
files = list_files_in_directory(path)
|
|
|
|
else:
|
|
|
|
print(f"'{path}' is neither a file nor a directory.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print("These files will be uploaded:")
|
|
|
|
for item in files:
|
|
|
|
print(item)
|
|
|
|
confirmation = input("Proceed? (y/n): ").strip().lower()
|
|
|
|
|
|
|
|
if confirmation != 'y':
|
|
|
|
print("Cancelling operation")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
file_data = []
|
|
|
|
for item in files:
|
|
|
|
item_data = image_processing.get_image_data(item)
|
|
|
|
file_data.append(item_data)
|
|
|
|
|
2023-11-05 21:13:57 +00:00
|
|
|
# Collection of post URL's which can be used for sharing features
|
|
|
|
# Where the API used doesn't support responding with a URL, a status
|
|
|
|
# message is provided.
|
|
|
|
posts = {}
|
|
|
|
|
2023-11-05 23:58:53 +00:00
|
|
|
if load_config.config['pixelfed']['enable']:
|
|
|
|
print("Pixelfed publishing enabled")
|
|
|
|
import publish_pixelfed
|
|
|
|
posts['pixelfed'] = publish_pixelfed.upload(file_data)
|
|
|
|
|
2023-11-05 14:42:08 +00:00
|
|
|
if load_config.config['flickr']['enable']:
|
2023-11-05 15:21:52 +00:00
|
|
|
print("Flickr publishing enabled")
|
2023-11-05 14:42:08 +00:00
|
|
|
import publish_flickr
|
2023-11-05 21:13:57 +00:00
|
|
|
posts['flickr'] = publish_flickr.upload(file_data)
|
2023-11-05 15:21:52 +00:00
|
|
|
|
2023-11-05 23:58:53 +00:00
|
|
|
## Wait before boosing to ensure media has been processed
|
|
|
|
print("Waiting to ensure media has been uploaded and processed before boosting")
|
|
|
|
time.sleep(20)
|
|
|
|
|
2023-11-05 21:13:57 +00:00
|
|
|
|
|
|
|
if load_config.config['boost_mastodon']['enable']:
|
|
|
|
print("Mastodon Boost enabled")
|
|
|
|
import boost_mastodon
|
2023-11-05 23:58:53 +00:00
|
|
|
posts['mastodon_boost'] = boost_mastodon.boost(posts['pixelfed'])
|
2023-11-05 14:22:32 +00:00
|
|
|
|
|
|
|
def list_files_in_directory(directory):
|
|
|
|
top_level_items = os.listdir(directory)
|
|
|
|
full_paths = [os.path.join(directory, item) for item in top_level_items]
|
|
|
|
return full_paths
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|