Edit · File favorite kid photos
Describe what this automation should do and the assistant will write it.
Conversation
Describe what this automation should do and the assistant will write it.
Code
people = data_query({"source": "people", "name": {"in": ["Maya Bennett", "Theo Bennett"]}})
name_by_person = {p["id"]: p["name"] for p in people}
person_ids = [p["id"] for p in people]
moves = []
if person_ids:
links = data_query({"source": "people_face", "person_id": {"in": person_ids}})
person_by_face = {link["face_id"]: link["person_id"] for link in links}
face_ids = [link["face_id"] for link in links]
person_by_photo = {}
if face_ids:
faces = data_query({"source": "faces", "id": {"in": face_ids}})
for face in faces:
media_item_id = face["media_item_id"]
if media_item_id != None and media_item_id not in person_by_photo:
person_by_photo[media_item_id] = person_by_face[face["id"]]
media_item_ids = [pid for pid in person_by_photo]
if media_item_ids:
favorites = data_query({"source": "media_items", "favorite": {"eq": True}, "id": {"in": media_item_ids}})
total = len(favorites)
for i, row in enumerate(favorites):
if row["year"] and row["media_dir_id"]:
kid = name_by_person[person_by_photo[row["id"]]]
moves.append({
"media_item_id": row["id"],
"media_dir_id": row["media_dir_id"],
"target_path": kid + "/" + str(row["year"]),
})
report_progress(i + 1, total)
print("Filing " + str(len(moves)) + " favorite photo(s) of Maya Bennett & Theo Bennett into <kid>/<year> folders")
move_media_items(moves)