Skip to content

Commit

Permalink
Added example for metadata changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Dec 5, 2023
1 parent cb9c36d commit ed484f4
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/metadata_change_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Read an osxphotos export database and print out list of photos which had metadata changes at time of last export
Run this with `osxphotos run metadata_change_report.py <exported_database_path>`
"""

import pathlib
import sys

import click

from osxphotos._constants import OSXPHOTOS_EXPORT_DB
from osxphotos.cli.click_rich_echo import rich_echo as echo
from osxphotos.cli.click_rich_echo import rich_echo_error as echo_error
from osxphotos.export_db import ExportDB


@click.command()
@click.argument(
"export_path",
type=click.Path(exists=True, dir_okay=True, file_okay=False),
required=True,
)
@click.argument("export_db_path", type=click.Path(exists=True), required=False)
def main(export_path, export_db_path):
"""Read an osxphotos export database and print out list of photos for which
the metadata changed between the previous export and the most recent export.
You must pass the path to the osxphotos export directory and optionally the
export database as the arguments to this script.
For example:
osxphotos run metadata_change_report.py /path/to/export/ /path/to/.osxphotos_export.db
"""

export_path = pathlib.Path(export_path)
# assume it's the export folder
export_db_path = pathlib.Path(export_db_path) or export_path / OSXPHOTOS_EXPORT_DB
if not export_db_path.is_file():
echo_error(
f"[error]Error: could not find export database at {export_db_path}[/]"
)
sys.exit(1)

exportdb = ExportDB(export_db_path, export_path)
export_results = exportdb.get_export_results(0)
if not export_results:
echo_error(f"[error]No report results found[/]")
sys.exit(1)

echo(f"Export date: [date]{export_results.datetime}")
for filename in export_results.metadata_changed:
try:
uuid = exportdb.get_file_record(filename).uuid
except Exception as e:
uuid = None
echo(f"[filename]{filename}[/] ([uuid]{uuid}[/])")

sys.exit(0)


if __name__ == "__main__":
main()

0 comments on commit ed484f4

Please sign in to comment.