diff --git a/boost_mastodon.py b/boost_mastodon.py
index a797f75..eeb31d0 100644
--- a/boost_mastodon.py
+++ b/boost_mastodon.py
@@ -5,7 +5,6 @@ from mastodon import Mastodon
m = Mastodon(access_token=config['boost_mastodon']['token'], api_base_url=config['boost_mastodon']['server'])
def boost(url):
- url = "https://pixelfed.scot/i/web/post/626007326735984162"
search_results = m.search(url, resolve=True, exclude_unreviewed=False)
status_result_count = len(search_results['statuses'])
if status_result_count != 1:
diff --git a/image_processing.py b/image_processing.py
index 4689918..2102d75 100644
--- a/image_processing.py
+++ b/image_processing.py
@@ -19,6 +19,7 @@ def get_image_data(path: str):
'alt': alt_text,
'tags': tags
}
+ print(image_data['create'])
return image_data
def add_watermark(file_data):
diff --git a/main.py b/main.py
index 5c6da3a..c5aebb3 100644
--- a/main.py
+++ b/main.py
@@ -1,7 +1,7 @@
import load_config
import image_processing
-import os, sys
+import os, sys, time
####
# CURRENT ISSUES
@@ -49,22 +49,25 @@ def main():
# message is provided.
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']:
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
- # TESTING CALL:
- boost_mastodon.boost("e")
- #posts['mastodon_boost'] = boost_mastodon.boost(posts['pixelfed'])
+ posts['mastodon_boost'] = boost_mastodon.boost(posts['pixelfed'])
def list_files_in_directory(directory):
top_level_items = os.listdir(directory)
diff --git a/publish_pixelfed.py b/publish_pixelfed.py
index 4c640c3..68c2488 100644
--- a/publish_pixelfed.py
+++ b/publish_pixelfed.py
@@ -1,24 +1,34 @@
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'], "image/jpeg")
+ 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']} | {file['description']}
{tag_string}" # Date needs adding
+ 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
\ No newline at end of file
+ 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
\ No newline at end of file