Successfully auths and uploads to Flickr
This commit is contained in:
parent
1950ffc54a
commit
b2edd16356
@ -1,6 +1,7 @@
|
||||
import pyexiv2
|
||||
|
||||
def get_image_data(path: str):
|
||||
print(f"Opening file: {path}")
|
||||
img = pyexiv2.Image(path)
|
||||
xmp = img.read_xmp()
|
||||
create_date = xmp.get('Xmp.xmp.CreateDate', 'N/A')
|
||||
@ -18,4 +19,4 @@ def get_image_data(path: str):
|
||||
'alt': alt_text,
|
||||
'tags': tags
|
||||
}
|
||||
print(image_data)
|
||||
return image_data
|
||||
|
7
load_config.py
Normal file
7
load_config.py
Normal file
@ -0,0 +1,7 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
flickr_key = os.getenv('FLICKR_KEY')
|
||||
flickr_secret = os.getenv('FLICKR_SECRET')
|
50
main.py
50
main.py
@ -0,0 +1,50 @@
|
||||
import load_config
|
||||
import image_processing
|
||||
import load_config
|
||||
import publish_flickr
|
||||
|
||||
import os, sys
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: social-photos <directory_or_file_path>")
|
||||
else:
|
||||
path = sys.argv[1]
|
||||
|
||||
if not os.path.exists(path):
|
||||
print(f"'{path}' does not exist.")
|
||||
sys.exit(1)
|
||||
elif os.path.isfile(path):
|
||||
print(f"'{path}' is a file.")
|
||||
files = [path]
|
||||
elif os.path.isdir(path):
|
||||
print(f"'{path}' is a directory.")
|
||||
files = list_files_in_directory(path)
|
||||
else:
|
||||
print(f"'{path}' is neither a file nor a directory.")
|
||||
sys.exit(1)
|
||||
|
||||
print("These files will be uploaded:")
|
||||
for item in files:
|
||||
print(item)
|
||||
confirmation = input("Proceed? (y/n): ").strip().lower()
|
||||
|
||||
if confirmation != 'y':
|
||||
print("Cancelling operation")
|
||||
sys.exit(0)
|
||||
|
||||
file_data = []
|
||||
for item in files:
|
||||
item_data = image_processing.get_image_data(item)
|
||||
file_data.append(item_data)
|
||||
|
||||
print(file_data)
|
||||
publish_flickr.upload(file_data)
|
||||
|
||||
def list_files_in_directory(directory):
|
||||
top_level_items = os.listdir(directory)
|
||||
full_paths = [os.path.join(directory, item) for item in top_level_items]
|
||||
return full_paths
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,19 +1,27 @@
|
||||
import flickrapi
|
||||
import load_config
|
||||
|
||||
api_key =
|
||||
api_secret =
|
||||
print("Authenticating with Flickr")
|
||||
flickr = flickrapi.FlickrAPI(load_config.flickr_key, load_config.flickr_secret)
|
||||
flickr.authenticate_via_browser(perms='write')
|
||||
|
||||
flickr = flickrapi.FlickrAPI(api_key, api_secret)
|
||||
|
||||
def upload(file_data: dict):
|
||||
def upload(file_data: list):
|
||||
for file in file_data:
|
||||
print(file)
|
||||
flickr.upload(
|
||||
filename = file_data.path,
|
||||
title = file_data.title,
|
||||
description = file_data.description,
|
||||
tags = file_data.tags.join(" "),
|
||||
filename = file['path'],
|
||||
title = file['title'],
|
||||
description = file['description'],
|
||||
tags = prepareTags(file['tags']),
|
||||
is_public = 1,
|
||||
format = rest
|
||||
format = 'rest'
|
||||
)
|
||||
|
||||
def prepareTags(tags: list):
|
||||
return None
|
||||
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)
|
BIN
test_files/_IGP1936_02.jpg
Normal file
BIN
test_files/_IGP1936_02.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 MiB |
Loading…
Reference in New Issue
Block a user