Possible gramplet for merging based on family Search ID?

from gramps.gen.display.grampletpopup import GrampletPopup

class MergeDuplicatesGramplet(GrampletPopup):
    def __init__(self, db, person, view):
        GrampletPopup.__init__(self, db, person, view)
        self.title = _("Merge Duplicates Gramplet")
        self.icon = 'merge'

    def init(self):
        self.make_button(_("Identify Duplicates"), self.identify_duplicates)

    def identify_duplicates(self, obj):
        # Dictionary to store _FSFTID values and their corresponding individuals
        fsftid_dict = {}

        # Iterate through all individuals in the database
        for handle in self.db.get_person_handles():
            person = self.db.get_person_from_handle(handle)
            fsftid = self.get_fsftid(person)
            
            if fsftid:
                if fsftid in fsftid_dict:
                    # Add the current individual to the list of duplicates
                    fsftid_dict[fsftid].append(person)
                else:
                    # Initialize a list with the current individual
                    fsftid_dict[fsftid] = [person]

        # Print or display information about duplicates
        for fsftid, individuals in fsftid_dict.items():
            if len(individuals) > 1:
                print(f"Duplicates for _FSFTID {fsftid}:")
                for individual in individuals:
                    print(f" - {individual.get_primary_name().get_value()} ({individual.handle})")
                print("\n")

    def get_fsftid(self, person):
        # Function to retrieve the _FSFTID attribute value for an individual
        fsftid_attr = person.get_attribute("_FSFTID")
        return fsftid_attr.get_value() if fsftid_attr else None

Register(MergeDuplicatesGramplet)

please keep in mind I had asked for help on this as I do not know Python. would something like this work? The goal would be to Identify duplicate imported information based on family search ID. what are your thoughts on this, is something missing? Would this work, if so how can I utilize this as a gramplet?

This looks like it tries to merge duplicate Persons
But there’s nothing that keeps it from resulting in People with duplicate secondary objects: Events, Citations, Notes.

You probably want to look at the source for the Isotammi MultiMerge gramplet and built-in Find Possible Duplicate People

You can run this sort of code through SuperTool. That allows avoiding the hassle of building a GUI for the operation.

I will look into the multimerge gramplet. I appreciate the thoughts.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.