Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brucejackson/3c32d64a991559fca5adf3562b3fdeed to your computer and use it in GitHub Desktop.
Save brucejackson/3c32d64a991559fca5adf3562b3fdeed to your computer and use it in GitHub Desktop.
[Gramps SuperTool script file]
version=1
[title]
Import Ancestry URL and ID numbers
[category]
People
[initial_statements]
#
# import classes
#
import pandas as pd
from urllib.parse import urlparse, parse_qs, unquote
from pathlib import PurePosixPath
from gramps.gen.lib import Attribute, AttributeType, Person, Url, UrlType
#
# Create objects. In this case, we are adding 2 attributes and 2 urls to each
# person.
#
attr = Attribute()
attr1 = Attribute()
attr_type = AttributeType()
attr1_type = AttributeType()
url_type = UrlType()
url = Url()
url1_type = UrlType()
url1 = Url()
#
# read the source csv file into a dataframe
#
df = pd.read_csv('/mnt/c/Users/Public/Documents/Genealogy-Gramps/SuperTool-Scripts/AncestryLibraryUntitled1a.csv')
#
# Parse the url and create a new column with the unique IDs.
# URL structure has IDs in the path https://www.ancestrylibrary.ca/family-tree/person/tree/26996426/person/1968625748
#
df['AncestryLibrary_TreeID'] = df.apply(lambda row: PurePosixPath(unquote(urlparse(row.AncestryTreeURL).path)).parts[4], axis=1)
df['AncestryLibrary_PersonID'] = df.apply(lambda row: PurePosixPath(unquote(urlparse(row.AncestryTreeURL).path)).parts[6], axis=1)
[statements]
#
# search for the row in the dataframe by gramps_id.
#
try:
ancestry_row = df.loc[df["gramps_id"] == gramps_id, ('AncestryLibrary_TreeID', 'AncestryLibrary_PersonID','AncestryTreeURL')]
#
# Convert the values to a string (without the row number) and assign to variables.
#
AncestryLibrary_TreeID = ancestry_row["AncestryLibrary_TreeID"].to_string(index=False)
Person_ID = ancestry_row["AncestryLibrary_PersonID"].to_string(index=False)
AncestryTreeURL = ancestry_row["AncestryTreeURL"].to_string(index=False)
objAncestryTreeURL = ancestry_row["AncestryTreeURL"]
#
# Test to make sure we have an result to parse.
#
if objAncestryTreeURL.size:
#
# set the attributes and urls and add to the person.
#
attr_type.set('Ancestry_Jackson_Tree_PersonID')
attr.set_type(attr_type)
attr.set_value(Person_ID)
person.add_attribute(attr)
attr1_type.set('Ancestry_Jackson_Tree_TreeID')
attr1.set_type(attr1_type)
attr1.set_value(AncestryLibrary_TreeID)
person.add_attribute(attr1)
url_type.set('AncestryLibrary_Jackson_Tree')
url.set_type(url_type)
url.set_path(AncestryTreeURL)
person.add_url(url)
url1_type.set('Ancestry_Jackson-Tree ($)')
url1.set_type(url1_type)
url1.set_path(AncestryTreeURL.replace('ancestrylibrary','ancestry'))
person.add_url(url1)
except:
print('no value found')
[filter]
[expressions]
[scope]
all
[unwind_lists]
True
[commit_changes]
True
[summary_only]
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment