keep_exporter/export.py
def delete_local_only_files(
    local_index: Dict[str, LocalNote],
    keep_notes: Dict[str, List[gkeepapi.node.Note]],
    delete_local: bool,
) -> Tuple[int, int]:
    """
    Checks the local index for any notes or media that exist only locally
    and were not returned in the Google Keep API call.
    """
    deleted_notes, deleted_media = 0, 0

    local_only_note_ids = set(local_index.keys()).difference(set(keep_notes.keys()))

    if local_only_note_ids:
        if not delete_local:
            click.echo(
                f"{len(local_only_note_ids)} notes exist locally, but not in Google Keep. Add argument [--delete-local] to delete."
            )
        else:
            click.echo(
                f"{len(local_only_note_ids)} notes exist locally, but not in Google Keep. Trashing local files."
            )
            for note_id in local_only_note_ids:
                note_path = local_index[note_id].path
                deleted_notes += 1
                if note_path:
                    click.echo(
                        f"    Deleting unknown local note [{note_id}] file [{local_index[note_id].path}]"
                    )
                    note_path.unlink()

    local_only_media: Set[Tuple[str, str]] = set(
        [
            (local_media.google_keep_note_id, local_media.google_keep_media_id)
            for local_note in local_index.values()
            for local_media in local_note.local_media.values()
            if local_media.google_keep_note_id and local_media.google_keep_media_id
        ]
    )

    notes: ValuesView[gkeepapi._node.Note] = keep_notes.values()
    keep_media: Set[Tuple[str, str]] = set(
        [
            (keep_note.id, keep_media.id)
            for keep_note in notes
            for keep_media in all_note_media(keep_note)
        ]
    )

    local_only_media_ids = local_only_media.difference(keep_media)
    if not local_only_media_ids:
        return (deleted_notes, 0)

    if not delete_local:
        click.echo(
            f"{len(local_only_note_ids)} media files exist locally, but not in Google Keep. Add argument [--delete-local] to delete."
        )
        return (deleted_notes, 0)

    for (note_id, media_id) in local_only_media_ids:
        media = local_index[note_id].local_media[media_id]

        click.echo(
            f"    Deleting media [{media_id}] for note [{note_id}] file [{media.path}]"
        )
        media.path.unlink()
        deleted_media += 1

    return (deleted_notes, deleted_media)

    Checks the local index for any notes or media that exist only locally
    and were not returned in the Google Keep API call.
    
Checks the local index for any notes or media that exist only locally
and were not returned in the Google Keep API call.
Checks the local index for any notes or media that exist only locally and were not returned in the Google Keep API call .
def delete_local_only_files(
    local_index: Dict[str, LocalNote],
    keep_notes: Dict[str, List[gkeepapi.node.Note]],
    delete_local: bool,
) -> Tuple[int, int]:
    deleted_notes, deleted_media = 0, 0
    local_only_note_ids = set(local_index.keys()).difference(set(keep_notes.keys()))
    if local_only_note_ids:
        if not delete_local:
            click.echo(
                f"{len(local_only_note_ids)} notes exist locally, but not in Google Keep. Add argument [--delete-local] to delete."
            )
        else:
            click.echo(
                f"{len(local_only_note_ids)} notes exist locally, but not in Google Keep. Trashing local files."
            )
            for note_id in local_only_note_ids:
                note_path = local_index[note_id].path
                deleted_notes += 1
                if note_path:
                    click.echo(
                        f"    Deleting unknown local note [{note_id}] file [{local_index[note_id].path}]"
                    )
                    note_path.unlink()
    local_only_media: Set[Tuple[str, str]] = set(
        [
            (local_media.google_keep_note_id, local_media.google_keep_media_id)
            for local_note in local_index.values()
            for local_media in local_note.local_media.values()
            if local_media.google_keep_note_id and local_media.google_keep_media_id
        ]
    )
    notes: ValuesView[gkeepapi._node.Note] = keep_notes.values()
    keep_media: Set[Tuple[str, str]] = set(
        [
            (keep_note.id, keep_media.id)
            for keep_note in notes
            for keep_media in all_note_media(keep_note)
        ]
    )
    local_only_media_ids = local_only_media.difference(keep_media)
    if not local_only_media_ids:
        return (deleted_notes, 0)
    if not delete_local:
        click.echo(
            f"{len(local_only_note_ids)} media files exist locally, but not in Google Keep. Add argument [--delete-local] to delete."
        )
        return (deleted_notes, 0)
    for (note_id, media_id) in local_only_media_ids:
        media = local_index[note_id].local_media[media_id]
        click.echo(
            f"    Deleting media [{media_id}] for note [{note_id}] file [{media.path}]"
        )
        media.path.unlink()
        deleted_media += 1
    return (deleted_notes, deleted_media)
def delete_local_only_files ( local_index : Dict [ str , LocalNote ] , keep_notes : Dict [ str , List [ gkeepapi . node . Note ] ] , delete_local : bool , ) -> Tuple [ int , int ] : deleted_notes , deleted_media = 0 , 0 local_only_note_ids = set ( local_index . keys ( ) ) . difference ( set ( keep_notes . keys ( ) ) ) if local_only_note_ids : if not delete_local : click . echo ( f"{len(local_only_note_ids)} notes exist locally, but not in Google Keep. Add argument [--delete-local] to delete." ) else : click . echo ( f"{len(local_only_note_ids)} notes exist locally, but not in Google Keep. Trashing local files." ) for note_id in local_only_note_ids : note_path = local_index [ note_id ] . path deleted_notes += 1 if note_path : click . echo ( f"    Deleting unknown local note [{note_id}] file [{local_index[note_id].path}]" ) note_path . unlink ( ) local_only_media : Set [ Tuple [ str , str ] ] = set ( [ ( local_media . google_keep_note_id , local_media . google_keep_media_id ) for local_note in local_index . values ( ) for local_media in local_note . local_media . values ( ) if local_media . google_keep_note_id and local_media . google_keep_media_id ] ) notes : ValuesView [ gkeepapi . _node . Note ] = keep_notes . values ( ) keep_media : Set [ Tuple [ str , str ] ] = set ( [ ( keep_note . id , keep_media . id ) for keep_note in notes for keep_media in all_note_media ( keep_note ) ] ) local_only_media_ids = local_only_media . difference ( keep_media ) if not local_only_media_ids : return ( deleted_notes , 0 ) if not delete_local : click . echo ( f"{len(local_only_note_ids)} media files exist locally, but not in Google Keep. Add argument [--delete-local] to delete." ) return ( deleted_notes , 0 ) for ( note_id , media_id ) in local_only_media_ids : media = local_index [ note_id ] . local_media [ media_id ] click . echo ( f"    Deleting media [{media_id}] for note [{note_id}] file [{media.path}]" ) media . path . unlink ( ) deleted_media += 1 return ( deleted_notes , deleted_media )
Checks the local index for any notes or media that exist only locally
and were not returned in the Google Keep API call.
Checks the local index for any notes or media that exist only locally and were not returned in the Google Keep API call .
"""
    Checks the local index for any notes or media that exist only locally
    and were not returned in the Google Keep API call.
    """
local_index
Dict[str, LocalNote]
keep_notes
Dict[str, List[gkeepapi.node.Note]]
delete_local
bool