How set certain place for all Marriage events which specific conditions?

I have about 2 thousands of wrong or empty places in Marriage events.

I need find all Marriages which have exact full date like “1800-01-01” && have citation (no need iterate citations - the first found is OK). At the same time citation should have media with name which contains string “metrik_wedding_bilovody_”.
For all these Marriage-events I need set place “P0329”.
Something similar I need do with another search strings and another places’ ids.

It it possible change all them using scripts? How can I do this?

This can be done with the following Supertool script:

[Gramps SuperTool script file]
version=1

[title]
fix-events

[description]

[category]
Events

[initial_statements]
place = db.get_place_from_gramps_id("P0329")
n = 0
def ok():
    if not date: return False
    if date.obj.modifier != Date.MOD_NONE: return False
    ymd = date.obj.get_ymd()
    if ymd[0] == 0: return False
    if ymd[1] == 0: return False
    if ymd[2] == 0: return False
    if len(citations) == 0: return False
    c = citations[0]
    for mediaref in c.obj.get_media_list():
	    media = db.get_media_from_handle(mediaref.ref)
	    if 'metrik_wedding_bilovody_' in media.desc:
		    return True
    return False

[statements]
if ok():
    event.set_place_handle(place.handle)
    n += 1

[filter]

[expressions]
"Number of updated events:", n

[scope]
all

[unwind_lists]
False

[commit_changes]
True

[summary_only]
True


If I understood the scenario correctly.

Supertool is an advanced tool and can be installed with these instructions:

Some documentation here: isotammi-addons/source/SuperTool/README.md at master · Taapeli/isotammi-addons · GitHub

Hope this helps, let me know how it goes.

2 Likes

Yeah, this is exactly what I need. I only added several more conditions and ids logging.

[Gramps SuperTool script file]
version=1

[title]
fix-events

[description]

[category]
Events

[initial_statements]
place = db.get_place_from_gramps_id("P0329")
n = 0
ids: str = ''

def ok():
    if not type == 'Marriage': return False
    if not date: return False
    if date.obj.modifier != Date.MOD_NONE: return False
    if int(date.obj.get_year()) > 1919: return False
    ymd = date.obj.get_ymd()
    if ymd[0] == 0: return False
    if ymd[1] == 0: return False
    if ymd[2] == 0: return False
    if len(citations) == 0: return False
    c = citations[0]
    for mediaref in c.obj.get_media_list():
	    media = db.get_media_from_handle(mediaref.ref)
	    if 'metrik_wedding_bilovody_' in media.desc:
		    return True
    return False

[statements]
if ok():
    event.set_place_handle(place.handle)
    ids = ids + '|(\\b' + gramps_id + '\\b)'
    n += 1

[filter]

[expressions]
"Number of updated events:", n,
"Events ids:", ids

[scope]
all

[unwind_lists]
False

[commit_changes]
True

[summary_only]
True

PS: This is my first usage of SuperTool, but this is amazing! Earlier I used export, and parsed xml in Laravel because I dont know Python syntax. But looks like this syntax isnt so difficult.
Thank you!

I can be useful to have a script documented. And AIs are becoming adept that that.

Asked Perplexity.ai to “please assess the following Python and describe in plain english:” & pasted in the SuperTool script.

Gramps SuperTool Script Assessment

The provided Gramps SuperTool script appears to be a script that is designed to fix the events in a Gramps database. Let’s take a closer look at what the script is doing:

Initial Statements

  1. The script retrieves a place object from the database using the Gramps ID “P0329”.
  2. The script initializes a variable n to keep track of the number of updated events.
  3. The script initializes an empty string variable ids to store the Gramps IDs of the updated events.

ok() Function

The ok() function performs a series of checks on the event data and returns True if the event meets the criteria, and False otherwise. The function checks the following:

  1. Whether the event type is “Marriage”.
  2. Whether the event has a date.
  3. Whether the date modifier is not “NONE”.
  4. Whether the year of the event is greater than 1919.
  5. Whether the year, month, and day components of the date are all non-zero.
  6. Whether the event has at least one citation.
  7. Whether the first citation has a media reference with a description containing the string “metrik_wedding_bilovody_”.

Statements

The script iterates through the events in the database and checks if the ok() function returns True for each event. If the event passes the checks, the script does the following:

  1. Sets the place handle of the event to the handle of the place object retrieved earlier.
  2. Appends the Gramps ID of the event to the ids string, enclosed in \b (word boundary) characters.
  3. Increments the n variable.

Filter, Expressions, Scope, Unwind Lists, Commit Changes, and Summary Only

These sections of the script define the behavior of the SuperTool script:

  • Filter: This section is empty, so the script will process all events in the database.
  • Expressions: This section displays the number of updated events and the Gramps IDs of the updated events.
  • Scope: This section is set to “all”, meaning the script will process all events in the database.
  • Unwind Lists: This section is set to False, meaning the script will not unwind any lists.
  • Commit Changes: This section is set to True, meaning the script will commit the changes to the database.
  • Summary Only: This section is set to True, meaning the script will only display a summary of the changes and not show the details of each individual event.

Potential Use Case

This Gramps SuperTool script appears to be designed to fix issues with marriage events in the Gramps database. The ok() function performs a series of checks on the event data, and if the event meets the criteria, the script updates the place handle of the event and keeps track of the Gramps IDs of the updated events.

This script could be useful for users who have a Gramps database with problematic marriage event data, and they want to automatically fix the issues in a batch process.

1 Like

@Urchello

Could you do an experiment and see how well Perplexity.ai does when asked to assess and describe the script in YOUR native language?

@emyoulation are you using free Perplexity.ai? I tried on natine language and English and received answer one paragraph only. More detailed question gived more details but anyway I didnt receive what I asked. It not added comments in directly in the script.
A bit better answer I received from chat.openai.com. It added comments, but it removed another sections like [title]. I can fopce it dont remove original sections. This is also free tariff plan.

# This script aims to correct events in the Gramps genealogy program. 
# It checks all events of type "Marriage" that occurred before 1920, have a specified date and place, 
# and are associated with sources (citations) containing relevant media files. 
# If such an event is found, it is automatically updated by setting the event place to the one specified in the variable place. 
# Additionally, it counts the number of updated events and stores their identifiers. 
# After the script execution, it outputs the number of updated events and their identifiers.

# Initializations
place = db.get_place_from_gramps_id("P0329")  # Get the place object for later use
n = 0  # Variable to count the number of updated events
ids: str = ''  # String to store the identifiers of updated events

# Function to check if an event meets the criteria for updating
def ok():
    # Check event type
    if not type == 'Marriage': return False  
    # Check event date availability
    if not date: return False  
    # Check absence of date modifiers
    if date.obj.modifier != Date.MOD_NONE: return False  
    # Check event year
    if int(date.obj.get_year()) > 1919: return False  
    ymd = date.obj.get_ymd()
    # Check year presence in date
    if ymd[0] == 0: return False  
    # Check month presence in date
    if ymd[1] == 0: return False  
    # Check day presence in date
    if ymd[2] == 0: return False  
    # Check event sources existence
    if len(citations) == 0: return False  
    c = citations[0]  # Get the first source for the event
    for mediaref in c.obj.get_media_list():
        media = db.get_media_from_handle(mediaref.ref)  # Get media files associated with the source
        if 'metrik_wedding_bilovody_' in media.desc:  # Check media file description
            return True  # Return True if relevant media file found
    return False  # Return False if conditions are not met

And the most close answer what I asked, I got from Gemini:

# Gramps SuperTool script file
version=1

# Назва
[title]
fix-events

# Опис
# Цей скрипт використовується для виправлення подій у Gramps SuperTool. 
# Він шукає шлюби, які відбулися до 1920 року, мають посилання на джерело 
# з описом "metrik_wedding_bilovody_" і не мають місця проведення. 
# Якщо такі події знаходяться, скрипт присвоює їм місце проведення з ID "P0329".

# Категорія
[category]
Events

# Початкові дії
[initial_statements]
# Змінна для зберігання місця проведення
# (ID "P0329")
place = db.get_place_from_gramps_id("P0329")

# Лічильник оновлених подій
n = 0

# Змінна для зберігання ID оновлених подій
ids: str = ''

# Функція для перевірки, чи подія відповідає критеріям
def ok():
    # Перевірка типу події
    if not type == 'Marriage': return False

    # Перевірка наявності дати
    if not date: return False

    # Перевірка модифікатора дати
    if date.obj.modifier != Date.MOD_NONE: return False

    # Перевірка року
    if int(date.obj.get_year()) > 1919: return False

    # Перевірка дати
    ymd = date.obj.get_ymd()
    if ymd[0] == 0: return False
    if ymd[1] == 0: return False
    if ymd[2] == 0: return False

    # Перевірка наявності джерела
    if len(citations) == 0: return False

    # Перевірка опису джерела
    c = citations[0]
    for mediaref in c.obj.get_media_list():
	    media = db.get_media_from_handle(mediaref.ref)
	    if 'metrik_wedding_bilovody_' in media.desc:
		    return True
    return False

# Основні дії
[statements]
# Перевірка події
if ok():
    # Встановлення місця проведення
    event.set_place_handle(place.handle)

    # Збільшення лічильника
    n += 1

    # Збереження ID події
    ids = ids + '|(\\b' + gramps_id + '\\b)'

# Фільтр
[filter]

# Вирази
[expressions]
# Кількість оновлених подій
"Number of updated events:", n,

# ID оновлених подій
"Events ids:", ids

# Область застосування
[scope]
all

# Розгортання списків
[unwind_lists]
False

# Зберегти зміни
[commit_changes]
True

# Тільки підсумок
[summary_only]
True
1 Like

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