social-photos/social_photos/publish_flickr.py

27 lines
873 B
Python
Raw Normal View History

2023-11-04 22:37:28 +00:00
import flickrapi
2023-11-18 10:25:23 +00:00
from . import load_config
2023-11-04 22:37:28 +00:00
print("Authenticating with Flickr")
2023-11-05 14:42:08 +00:00
flickr = flickrapi.FlickrAPI(load_config.config['flickr']['app_api'], load_config.config['flickr']['app_secret'])
flickr.authenticate_via_browser(perms='write')
2023-11-04 22:37:28 +00:00
def upload(file_data: list):
for file in file_data:
flickr.upload(
filename = file['path'],
title = file['title'],
2023-11-05 19:20:03 +00:00
description = file['description'] + load_config.config['flickr']['add_to_description'],
tags = prepareTags(file['tags']),
is_public = 1,
format = 'rest'
)
2023-11-05 14:42:08 +00:00
print("Uploading to Flickr")
2023-11-04 22:37:28 +00:00
def prepareTags(input_list: list):
output_list = []
for item in input_list:
if ' ' in item:
output_list.append(f"'{item}'")
else:
output_list.append(item)
return ' '.join(output_list)