How to use the osxphotos.PhotosDB function in osxphotos

To help you get started, we’ve selected a few osxphotos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RhetTbull / osxphotos / tests / test_movies_4_0.py View on Github external
def test_isphoto():
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=[UUID_DICT["image"]])

    assert photos[0].isphoto
    assert not photos[0].ismovie
github RhetTbull / osxphotos / tests / test_export_catalina_10_15_1.py View on Github external
def test_export_4():
    # test user supplied file already exists and test increment=True (default)
    import os
    import os.path
    import pathlib
    import tempfile
    import time

    import osxphotos

    tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
    dest = tempdir.name
    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=[UUID_DICT["export"]])

    timestamp = time.time()
    filename = f"osxphotos-export-2-test-{timestamp}.jpg"
    filename2 = f"osxphotos-export-2-test-{timestamp} (1).jpg"
    expected_dest = os.path.join(dest, filename)
    expected_dest_2 = os.path.join(dest, filename2)

    got_dest = photos[0].export(dest, filename)[0]
    got_dest_2 = photos[0].export(dest, filename)[0]

    assert got_dest_2 == expected_dest_2
    assert os.path.isfile(got_dest_2)
github RhetTbull / osxphotos / tests / test_catalina_10_15_1.py View on Github external
def test_export_9():
    # try to export edited file that's not edited
    # should raise exception
    import os
    import os.path
    import tempfile

    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
    dest = tempdir.name
    photos = photosdb.photos(uuid=[UUID_DICT["no_adjustments"]])

    filename = photos[0].filename

    with pytest.raises(Exception) as e:
        assert photos[0].export(dest, edited=True)
    assert e.type == ValueError
github RhetTbull / osxphotos / tests / test_template.py View on Github external
def test_subst_locale_1():
    """ Test that substitutions are correct in user locale"""
    import locale
    import osxphotos

    # osxphotos.template sets local on load so set the environment first
    # set locale to DE
    locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
    photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]

    for template in TEMPLATE_VALUES_DEU:
        rendered, _ = photo.render_template(template)
        assert rendered[0] == TEMPLATE_VALUES_DEU[template]
github RhetTbull / osxphotos / tests / test_mojave_10_14_6.py View on Github external
def test_album_sort_order():
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    album = [a for a in photosdb.album_info if a.title == "Pumpkin Farm"][0]
    photos = album.photos

    uuids = [p.uuid for p in photos]
    assert uuids == ALBUM_SORT_ORDER
github RhetTbull / osxphotos / tests / test_export_mojave_10_14_6.py View on Github external
def test_export_12():
    # export edited file with default name
    import os
    import os.path
    import pathlib
    import tempfile

    import osxphotos

    tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_")
    dest = tempdir.name
    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]])

    edited_name = pathlib.Path(photos[0].path_edited).name
    edited_suffix = pathlib.Path(edited_name).suffix
    filename = pathlib.Path(photos[0].filename).stem + "_edited" + edited_suffix
    expected_dest = os.path.join(dest, filename)

    got_dest = photos[0].export(dest, edited=True)[0]
    assert got_dest == expected_dest
github RhetTbull / osxphotos / tests / test_template.py View on Github external
def test_lookup_multi():
    """ Test that a lookup is returned for every possible value """
    import os
    import re
    import osxphotos
    from osxphotos.phototemplate import (
        TEMPLATE_SUBSTITUTIONS_MULTI_VALUED,
        PhotoTemplate,
    )

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
    photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
    template = PhotoTemplate(photo)

    for subst in TEMPLATE_SUBSTITUTIONS_MULTI_VALUED:
        lookup_str = re.match(r"\{([^\\,}]+)\}", subst).group(1)
        lookup = template.get_template_value_multi(lookup_str, path_sep=os.path.sep)
        assert isinstance(lookup, list)
        assert len(lookup) >= 1
github RhetTbull / osxphotos / tests / test_modified_date_mojave_10_14_6.py View on Github external
def test_modified():
    import datetime
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=[UUID_DICT["modified"]])
    assert photos[0].date_modified is not None
    assert photos[0].date_modified.isoformat() == "2019-12-01T11:43:45.714123-04:00"
github RhetTbull / osxphotos / tests / test_places_catalina_10_15_1.py View on Github external
def test_place_place_info_2():
    # test valid place info
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photo = photosdb.photos(uuid=[UUID_DICT["place_maui"]])[0]

    assert isinstance(photo.place, osxphotos.placeinfo.PlaceInfo)
    assert photo.place is not None
    assert not photo.place.ishome
    assert photo.place.name == "Maui, Wailea, Hawai'i, United States"
    assert photo.place.names.street_address == ["3700 Wailea Alanui Dr"]
    assert photo.place.names.city == ["Wailea", "Kihei", "Kihei"]
    assert photo.place.names.region == ["Maui"]
    assert photo.place.names.sub_administrative_area == ["Maui"]
    assert photo.place.names.state_province == ["Hawai'i"]
    assert photo.place.names.country == ["United States"]

    assert photo.place.country_code == "US"
    assert (
        photo.place.address_str
github RhetTbull / osxphotos / osxphotos / __main__.py View on Github external
not_selfie=None,
    panorama=None,
    not_panorama=None,
    has_raw=None,
    place=None,
    no_place=None,
    label=None,
    deleted=False,
    deleted_only=False,
):
    """ run a query against PhotosDB to extract the photos based on user supply criteria 
        used by query and export commands 
        arguments must be passed in same order as query and export 
        if either is modified, need to ensure all three functions are updated """

    photosdb = osxphotos.PhotosDB(dbfile=db)
    if deleted or deleted_only:
        photos = photosdb.photos(
            uuid=uuid,
            images=isphoto,
            movies=ismovie,
            from_date=from_date,
            to_date=to_date,
            intrash=True,
        )
    else:
        photos = []
    if not deleted_only:
        photos += photosdb.photos(
            uuid=uuid,
            images=isphoto,
            movies=ismovie,