How to use the osxphotos.utils._open_sql_file 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 / osxphotos / photosdb / photosdb.py View on Github external
def _get_db_version(self, db_file):
        """ Gets the Photos DB version from LiGlobals table

        Args:
            db_file: path to database file containing LiGlobals table

        Returns: version as str
        """

        version = None

        (conn, c) = _open_sql_file(db_file)

        # get database version
        c.execute(
            "SELECT value from LiGlobals where LiGlobals.keyPath is 'libraryVersion'"
        )
        version = c.fetchone()[0]
        conn.close()

        if version not in _TESTED_DB_VERSIONS:
            print(
                f"WARNING: Only tested on database versions [{', '.join(_TESTED_DB_VERSIONS)}]"
                + f" You have database version={version} which has not been tested"
            )

        return version
github RhetTbull / osxphotos / osxphotos / photosdb / photosdb.py View on Github external
def _process_database5(self):
        """ process the Photos database to extract info 
            works on Photos version >= 5.0 

            This is a big hairy 700 line function that should probably be refactored
            but it works so don't touch it.
        """

        if _debug():
            logging.debug(f"_process_database5")

        # Epoch is Jan 1, 2001
        td = (datetime(2001, 1, 1, 0, 0) - datetime(1970, 1, 1, 0, 0)).total_seconds()

        (conn, c) = _open_sql_file(self._tmp_db)

        # Look for all combinations of persons and pictures
        if _debug():
            logging.debug(f"Getting information about persons")

        # get info to associate persons with photos
        # then get detected faces in each photo and link to persons
        c.execute(
            """ SELECT
                ZPERSON.Z_PK,
                ZPERSON.ZPERSONUUID,
                ZPERSON.ZFULLNAME,
                ZPERSON.ZFACECOUNT,
                ZPERSON.ZKEYFACE,
                ZPERSON.ZDISPLAYNAME
                FROM ZPERSON
github RhetTbull / osxphotos / osxphotos / photosdb / _photosdb_process_exif.py View on Github external
def _process_exifinfo_5(photosdb):
    """ process exif info for Photos >= 5 
        photosdb: PhotosDB instance """

    db = photosdb._tmp_db

    (conn, cursor) = _open_sql_file(db)

    result = conn.execute(
        """
        SELECT ZGENERICASSET.ZUUID, ZEXTENDEDATTRIBUTES.*
        FROM ZGENERICASSET
        JOIN ZEXTENDEDATTRIBUTES
        ON ZEXTENDEDATTRIBUTES.ZASSET = ZGENERICASSET.Z_PK
        """
    )

    photosdb._db_exifinfo_uuid = {}
    cols = [c[0] for c in result.description]
    for row in result.fetchall():
        record = dict(zip(cols, row))
        uuid = record["ZUUID"]
        if uuid in photosdb._db_exifinfo_uuid:
github RhetTbull / osxphotos / osxphotos / photosdb / _photosdb_process_searchinfo.py View on Github external
if self._db_version <= _PHOTOS_4_VERSION:
        raise NotImplementedError(
            f"search info not implemented for this database version"
        )

    search_db_path = pathlib.Path(self._dbfile).parent / "search" / "psi.sqlite"
    if not search_db_path.exists():
        logging.warning(f"could not find search db: {search_db_path}")
        return None

    if _db_is_locked(search_db_path):
        search_db = self._copy_db_file(search_db_path)
    else:
        search_db = search_db_path

    (conn, c) = _open_sql_file(search_db)

    result = c.execute(
        """
        select
        ga.rowid,
        assets.uuid_0,
        assets.uuid_1,
        groups.rowid as groupid,
        groups.category,
        groups.owning_groupid,
        groups.content_string,
        groups.normalized_string,
        groups.lookup_identifier
        from
        ga
        join groups on groups.rowid = ga.groupid
github RhetTbull / osxphotos / osxphotos / photosdb / photosdb.py View on Github external
def get_db_connection(self):
        """ Get connection to the working copy of the Photos database 

        Returns:
            tuple of (connection, cursor) to sqlite3 database
        """
        return _open_sql_file(self._tmp_db)
github RhetTbull / osxphotos / osxphotos / photosdb / photosdb.py View on Github external
def _process_database4(self):
        """ process the Photos database to extract info
            works on Photos version <= 4.0 """

        # Epoch is Jan 1, 2001
        td = (datetime(2001, 1, 1, 0, 0) - datetime(1970, 1, 1, 0, 0)).total_seconds()

        (conn, c) = _open_sql_file(self._tmp_db)

        # get info to associate persons with photos
        # then get detected faces in each photo and link to persons
        c.execute(
            """ SELECT
                RKPerson.modelID,
                RKPerson.uuid,
                RKPerson.name,
                RKPerson.faceCount,
                RKPerson.displayName,
                RKPerson.representativeFaceId
                FROM RKPerson
            """
        )

        # 0     RKPerson.modelID,