keep_exporter/export.py
def index_existing_files(directory: pathlib.Path) -> Dict[str, LocalNote]:
    """
    Scans the output folder looking for existing markdown files
    and media files and builds an index by google_keep_id of those files
    using the metadata in the markdown frontmatter and the filenames
    of the media files.
    """
    index: Dict[str, LocalNote] = {}

    keep_notes = 0
    unknown_notes = 0
    errors = 0
    media = 0

    for file in directory.rglob("*"):
        if not file.is_file():
            continue

        # markdown file
        if file.name.endswith(".md"):
            try:
                with open(file, "r") as f:
                    fm = frontmatter.load(f)

                    google_keep_id: str = fm.metadata.get("google_keep_id")
                    if google_keep_id:
                        if google_keep_id in index and index[google_keep_id].path:
                            click.echo(
                                f"Same Google Keep ID {google_keep_id} in multiple files:\n"
                                f"    {file}\n"
                                f"    {index[google_keep_id].path}\n"
                                f"Only the last file will be updated."
                            )

                        keep_notes += 1
                        index.setdefault(google_keep_id, LocalNote(google_keep_id))

                        updated: datetime.datetime = datetime.datetime.fromtimestamp(
                            fm.metadata.get("timestamps", {}).get("updated")
                        )

                        index[google_keep_id].timestamp_updated = updated
                        index[google_keep_id].path = file
                    else:
                        unknown_notes += 1

            except IOError as ex:
                errors = 0
                click.echo(
                    "Unable to open Markdown file [{os.path.join(root, file)}]. Skipping: {str(ex)}",
                    err=True,
                )

        # media file
        else:
            media += 1

            google_keep_id = file.parent.name
            media_id = ".".join(file.name.split(".")[0:2])

            index.setdefault(google_keep_id, LocalNote(google_keep_id))
            index[google_keep_id].local_media[media_id] = LocalMedia(
                file, google_keep_id, media_id
            )

    click.echo(
        f"Indexed local files: {keep_notes} Google Keep notes, {unknown_notes} unknown markdown files, {media} media files, {errors} errors"
    )

    return index

    Scans the output folder looking for existing markdown files
    and media files and builds an index by google_keep_id of those files
    using the metadata in the markdown frontmatter and the filenames
    of the media files.
    
Scans the output folder looking for existing markdown files
and media files and builds an index by google_keep_id of those files
using the metadata in the markdown frontmatter and the filenames
of the media files.
Scans the output folder looking for existing markdown files and media files and builds an index by google_keep_id of those files using the metadata in the markdown frontmatter and the filenames of the media files .
def index_existing_files(directory: pathlib.Path) -> Dict[str, LocalNote]:
    index: Dict[str, LocalNote] = {}
    keep_notes = 0
    unknown_notes = 0
    errors = 0
    media = 0
    for file in directory.rglob("*"):
        if not file.is_file():
            continue
        if file.name.endswith(".md"):
            try:
                with open(file, "r") as f:
                    fm = frontmatter.load(f)
                    google_keep_id: str = fm.metadata.get("google_keep_id")
                    if google_keep_id:
                        if google_keep_id in index and index[google_keep_id].path:
                            click.echo(
                                f"Same Google Keep ID {google_keep_id} in multiple files:\n"
                                f"    {file}\n"
                                f"    {index[google_keep_id].path}\n"
                                f"Only the last file will be updated."
                            )
                        keep_notes += 1
                        index.setdefault(google_keep_id, LocalNote(google_keep_id))
                        updated: datetime.datetime = datetime.datetime.fromtimestamp(
                            fm.metadata.get("timestamps", {}).get("updated")
                        )
                        index[google_keep_id].timestamp_updated = updated
                        index[google_keep_id].path = file
                    else:
                        unknown_notes += 1
            except IOError as ex:
                errors = 0
                click.echo(
                    "Unable to open Markdown file [{os.path.join(root, file)}]. Skipping: {str(ex)}",
                    err=True,
                )
        else:
            media += 1
            google_keep_id = file.parent.name
            media_id = ".".join(file.name.split(".")[0:2])
            index.setdefault(google_keep_id, LocalNote(google_keep_id))
            index[google_keep_id].local_media[media_id] = LocalMedia(
                file, google_keep_id, media_id
            )
    click.echo(
        f"Indexed local files: {keep_notes} Google Keep notes, {unknown_notes} unknown markdown files, {media} media files, {errors} errors"
    )
    return index
def index_existing_files ( directory : pathlib . Path ) -> Dict [ str , LocalNote ] : index : Dict [ str , LocalNote ] = { } keep_notes = 0 unknown_notes = 0 errors = 0 media = 0 for file in directory . rglob ( "*" ) : if not file . is_file ( ) : continue if file . name . endswith ( ".md" ) : try : with open ( file , "r" ) as f : fm = frontmatter . load ( f ) google_keep_id : str = fm . metadata . get ( "google_keep_id" ) if google_keep_id : if google_keep_id in index and index [ google_keep_id ] . path : click . echo ( f"Same Google Keep ID {google_keep_id} in multiple files:\n" f"    {file}\n" f"    {index[google_keep_id].path}\n" f"Only the last file will be updated." ) keep_notes += 1 index . setdefault ( google_keep_id , LocalNote ( google_keep_id ) ) updated : datetime . datetime = datetime . datetime . fromtimestamp ( fm . metadata . get ( "timestamps" , { } ) . get ( "updated" ) ) index [ google_keep_id ] . timestamp_updated = updated index [ google_keep_id ] . path = file else : unknown_notes += 1 except IOError as ex : errors = 0 click . echo ( "Unable to open Markdown file [{os.path.join(root, file)}]. Skipping: {str(ex)}" , err = True , ) else : media += 1 google_keep_id = file . parent . name media_id = "." . join ( file . name . split ( "." ) [ 0 : 2 ] ) index . setdefault ( google_keep_id , LocalNote ( google_keep_id ) ) index [ google_keep_id ] . local_media [ media_id ] = LocalMedia ( file , google_keep_id , media_id ) click . echo ( f"Indexed local files: {keep_notes} Google Keep notes, {unknown_notes} unknown markdown files, {media} media files, {errors} errors" ) return index
Scans the output folder looking for existing markdown files
and media files and builds an index by google_keep_id of those files
using the metadata in the markdown frontmatter and the filenames
of the media files.
Scans the output folder looking for existing markdown files and media files and builds an index by google_keep_id of those files using the metadata in the markdown frontmatter and the filenames of the media files .
"""
    Scans the output folder looking for existing markdown files
    and media files and builds an index by google_keep_id of those files
    using the metadata in the markdown frontmatter and the filenames
    of the media files.
    """ # markdown file # media file
directory
pathlib.Path