import flickrapi
import load_config

print("Authenticating with Flickr")
flickr = flickrapi.FlickrAPI(load_config.config['flickr']['app_api'], load_config.config['flickr']['app_secret'])
flickr.authenticate_via_browser(perms='write')

def upload(file_data: list):
    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):
    output_list = []
    for item in input_list:
        if ' ' in item:
            output_list.append(f"'{item}'")
        else:
            output_list.append(item)
    return ' '.join(output_list)