import flickrapi
import load_config

print("Authenticating with Flickr")
flickr = flickrapi.FlickrAPI(load_config.flickr_key, load_config.flickr_secret)
flickr.authenticate_via_browser(perms='write')

def upload(file_data: list):
    for file in file_data:
        print(file)
        flickr.upload(
            filename = file['path'],
            title = file['title'],
            description = file['description'],
            tags = prepareTags(file['tags']),
            is_public = 1,
            format = 'rest'
        )

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)