Conversation

Describe what this automation should do and the assistant will write it.

Organize my favorite photos of Maya and Theo into folders by child and year.
I built an automation that follows their assigned faces to find each child's photos, keeps only favorites, and files them under <child>/<year>.
Photos with both kids should only move once. Show progress, and don't run it automatically—I want to test it first.
Updated. Each photo is filed once, moves are batched, progress is reported, and the automation is disabled with no trigger so you can review and test 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)