Compare commits
No commits in common. "f920ad6f156cfd2421dde5c7da93190ea9923c96" and "1950ffc54af8730bf21026a2a73db61c9225249e" have entirely different histories.
f920ad6f15
...
1950ffc54a
|
@ -1,6 +1,5 @@
|
||||||
include
|
include
|
||||||
bin
|
bin
|
||||||
conf.toml
|
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
from load_config import config
|
|
||||||
|
|
||||||
from mastodon import Mastodon
|
|
||||||
|
|
||||||
m = Mastodon(access_token=config['boost_mastodon']['token'], api_base_url=config['boost_mastodon']['server'])
|
|
||||||
|
|
||||||
def boost(url):
|
|
||||||
search_results = m.search(url, resolve=True, exclude_unreviewed=False)
|
|
||||||
status_result_count = len(search_results['statuses'])
|
|
||||||
if status_result_count != 1:
|
|
||||||
print("Unable to find status to boost")
|
|
||||||
return None
|
|
||||||
status_id = search_results['statuses'][0]['id']
|
|
||||||
print(f"Boosting status: {status_id}")
|
|
||||||
m.status_reblog(status_id, visibility="public")
|
|
||||||
m.status_favourite(status_id)
|
|
|
@ -1,7 +1,6 @@
|
||||||
import pyexiv2
|
import pyexiv2
|
||||||
|
|
||||||
def get_image_data(path: str):
|
def get_image_data(path: str):
|
||||||
print(f"Reading metadata: {path}")
|
|
||||||
img = pyexiv2.Image(path)
|
img = pyexiv2.Image(path)
|
||||||
xmp = img.read_xmp()
|
xmp = img.read_xmp()
|
||||||
create_date = xmp.get('Xmp.xmp.CreateDate', 'N/A')
|
create_date = xmp.get('Xmp.xmp.CreateDate', 'N/A')
|
||||||
|
@ -19,10 +18,4 @@ def get_image_data(path: str):
|
||||||
'alt': alt_text,
|
'alt': alt_text,
|
||||||
'tags': tags
|
'tags': tags
|
||||||
}
|
}
|
||||||
print(image_data['create'])
|
print(image_data)
|
||||||
return image_data
|
|
||||||
|
|
||||||
def add_watermark(file_data):
|
|
||||||
## Create a new image file in the same directory as the file_data['path'] and return
|
|
||||||
## a new file_data dictionary with the new image in place of file_data['path']
|
|
||||||
return file_data
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
import os, toml
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
config = toml.load("conf.toml")
|
|
78
main.py
78
main.py
|
@ -1,78 +0,0 @@
|
||||||
import load_config
|
|
||||||
import image_processing
|
|
||||||
|
|
||||||
import os, sys, time
|
|
||||||
|
|
||||||
####
|
|
||||||
# CURRENT ISSUES
|
|
||||||
####
|
|
||||||
#
|
|
||||||
# Pixelfed API doesn't honour newlines. - Possibly look at HTML formatting?
|
|
||||||
# Pixelfed publishing is missing date - Needs parsing and appending to description
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
# 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 = {}
|
|
||||||
|
|
||||||
if load_config.config['pixelfed']['enable']:
|
|
||||||
print("Pixelfed publishing enabled")
|
|
||||||
import publish_pixelfed
|
|
||||||
posts['pixelfed'] = publish_pixelfed.upload(file_data)
|
|
||||||
|
|
||||||
if load_config.config['flickr']['enable']:
|
|
||||||
print("Flickr publishing enabled")
|
|
||||||
import publish_flickr
|
|
||||||
posts['flickr'] = publish_flickr.upload(file_data)
|
|
||||||
|
|
||||||
## Wait before boosing to ensure media has been processed
|
|
||||||
print("Waiting to ensure media has been uploaded and processed before boosting")
|
|
||||||
time.sleep(20)
|
|
||||||
|
|
||||||
|
|
||||||
if load_config.config['boost_mastodon']['enable']:
|
|
||||||
print("Mastodon Boost enabled")
|
|
||||||
import boost_mastodon
|
|
||||||
posts['mastodon_boost'] = boost_mastodon.boost(posts['pixelfed'])
|
|
||||||
|
|
||||||
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()
|
|
|
@ -1,27 +1,19 @@
|
||||||
import flickrapi
|
import flickrapi
|
||||||
import load_config
|
|
||||||
|
|
||||||
print("Authenticating with Flickr")
|
api_key =
|
||||||
flickr = flickrapi.FlickrAPI(load_config.config['flickr']['app_api'], load_config.config['flickr']['app_secret'])
|
api_secret =
|
||||||
flickr.authenticate_via_browser(perms='write')
|
|
||||||
|
|
||||||
def upload(file_data: list):
|
flickr = flickrapi.FlickrAPI(api_key, api_secret)
|
||||||
for file in file_data:
|
|
||||||
flickr.upload(
|
|
||||||
filename = file['path'],
|
|
||||||
title = file['title'],
|
|
||||||
description = file['description'] + load_config.config['flickr']['add_to_description'],
|
|
||||||
tags = prepareTags(file['tags']),
|
|
||||||
is_public = 1,
|
|
||||||
format = 'rest'
|
|
||||||
)
|
|
||||||
print("Uploading to Flickr")
|
|
||||||
|
|
||||||
def prepareTags(input_list: list):
|
def upload(file_data: dict):
|
||||||
output_list = []
|
flickr.upload(
|
||||||
for item in input_list:
|
filename = file_data.path,
|
||||||
if ' ' in item:
|
title = file_data.title,
|
||||||
output_list.append(f"'{item}'")
|
description = file_data.description,
|
||||||
else:
|
tags = file_data.tags.join(" "),
|
||||||
output_list.append(item)
|
is_public = 1,
|
||||||
return ' '.join(output_list)
|
format = rest
|
||||||
|
)
|
||||||
|
|
||||||
|
def prepareTags(tags: list):
|
||||||
|
return None
|
|
@ -1,34 +0,0 @@
|
||||||
import load_config
|
|
||||||
|
|
||||||
from mastodon import Mastodon
|
|
||||||
import datetime, pytz
|
|
||||||
|
|
||||||
m = Mastodon(access_token=load_config.config['pixelfed']['token'], api_base_url=load_config.config['pixelfed']['server'])
|
|
||||||
|
|
||||||
def upload(file_data: list):
|
|
||||||
for file in file_data:
|
|
||||||
print("Uploading image to Pixelfed")
|
|
||||||
media_upload = m.media_post(file['path'], description=file['alt'])
|
|
||||||
print("Posting to Pixelfed")
|
|
||||||
post_upload = m.status_post(formatPost(file), media_ids = media_upload['id'], visibility="public")
|
|
||||||
print(post_upload)
|
|
||||||
return post_upload['url']
|
|
||||||
|
|
||||||
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']} | {formatDate(file['create'])} \n {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
|
|
||||||
|
|
||||||
def formatDate(input_date_str: str):
|
|
||||||
input_datetime = datetime.datetime.fromisoformat(input_date_str)
|
|
||||||
london_tz = pytz.timezone('Europe/London')
|
|
||||||
london_datetime = input_datetime.replace(tzinfo=pytz.utc).astimezone(london_tz)
|
|
||||||
output = london_datetime.strftime("%d/%m/%Y")
|
|
||||||
print(output)
|
|
||||||
return output
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.6 MiB |
Loading…
Reference in New Issue