All working except Facebook

This commit is contained in:
Fred Boniface 2023-11-05 23:58:53 +00:00
parent 7e78c1c5f0
commit f920ad6f15
4 changed files with 26 additions and 13 deletions

View File

@ -5,7 +5,6 @@ from mastodon import Mastodon
m = Mastodon(access_token=config['boost_mastodon']['token'], api_base_url=config['boost_mastodon']['server']) m = Mastodon(access_token=config['boost_mastodon']['token'], api_base_url=config['boost_mastodon']['server'])
def boost(url): def boost(url):
url = "https://pixelfed.scot/i/web/post/626007326735984162"
search_results = m.search(url, resolve=True, exclude_unreviewed=False) search_results = m.search(url, resolve=True, exclude_unreviewed=False)
status_result_count = len(search_results['statuses']) status_result_count = len(search_results['statuses'])
if status_result_count != 1: if status_result_count != 1:

View File

@ -19,6 +19,7 @@ def get_image_data(path: str):
'alt': alt_text, 'alt': alt_text,
'tags': tags 'tags': tags
} }
print(image_data['create'])
return image_data return image_data
def add_watermark(file_data): def add_watermark(file_data):

21
main.py
View File

@ -1,7 +1,7 @@
import load_config import load_config
import image_processing import image_processing
import os, sys import os, sys, time
#### ####
# CURRENT ISSUES # CURRENT ISSUES
@ -49,22 +49,25 @@ def main():
# message is provided. # message is provided.
posts = {} posts = {}
if load_config.config['flickr']['enable']:
print("Flickr publishing enabled")
import publish_flickr
posts['flickr'] = publish_flickr.upload(file_data)
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
posts['pixelfed'] = publish_pixelfed.upload(file_data) 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']: if load_config.config['boost_mastodon']['enable']:
print("Mastodon Boost enabled") print("Mastodon Boost enabled")
import boost_mastodon import boost_mastodon
# TESTING CALL: posts['mastodon_boost'] = boost_mastodon.boost(posts['pixelfed'])
boost_mastodon.boost("e")
#posts['mastodon_boost'] = boost_mastodon.boost(posts['pixelfed'])
def list_files_in_directory(directory): def list_files_in_directory(directory):
top_level_items = os.listdir(directory) top_level_items = os.listdir(directory)

View File

@ -1,24 +1,34 @@
import load_config import load_config
from mastodon import Mastodon from mastodon import Mastodon
import datetime, pytz
m = Mastodon(access_token=load_config.config['pixelfed']['token'], api_base_url=load_config.config['pixelfed']['server']) m = Mastodon(access_token=load_config.config['pixelfed']['token'], api_base_url=load_config.config['pixelfed']['server'])
def upload(file_data: list): def upload(file_data: list):
for file in file_data: for file in file_data:
print("Uploading image to Pixelfed") print("Uploading image to Pixelfed")
media_upload = m.media_post(file['path'], "image/jpeg") media_upload = m.media_post(file['path'], description=file['alt'])
print("Posting to Pixelfed") print("Posting to Pixelfed")
post_upload = m.status_post(formatPost(file), media_ids = media_upload['id'], visibility="public") post_upload = m.status_post(formatPost(file), media_ids = media_upload['id'], visibility="public")
print(post_upload)
return post_upload['url'] return post_upload['url']
def formatPost(file: dict): def formatPost(file: dict):
tag_string = formatTags(file['tags']) tag_string = formatTags(file['tags'])
if load_config.config['pixelfed']['add_to_description']: if load_config.config['pixelfed']['add_to_description']:
file['description'] = file['description'] + load_config.config['pixelfed']['add_to_description'] file['description'] = file['description'] + load_config.config['pixelfed']['add_to_description']
return f"{file['title']} | {file['description']}<br><br>{tag_string}" # Date needs adding return f"{file['title']} | {formatDate(file['create'])} \n {file['description']} \n {tag_string}"
def formatTags(tags: list): def formatTags(tags: list):
formatted_tags = ['#' + tag.title().replace(' ', '') for tag in tags] formatted_tags = ['#' + tag.title().replace(' ', '') for tag in tags]
formatted_tags_str = ' '.join(formatted_tags) formatted_tags_str = ' '.join(formatted_tags)
return formatted_tags_str 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