Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In addition to contributor names, also get email addresses and phone numbers #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _getmyancestors_ is a python3 package that downloads family trees in GEDCOM form

This program is now in production phase, but bugs might still be present. Features will be added on request. It is provided as is.

The project is maintained at https://github.com/Linekio/getmyancestors. Visit here for the latest version and more information.
The project is maintained at https://github.com/Linekio/getmyancestors. Visit there for the latest version and more information.

This script requires python3 and the modules indicated in the requirements.txt file. To install the modules, run in your terminal:

Expand All @@ -17,9 +17,9 @@ The easiest way to install _getmyancestors_ is to use pip:

`pip install getmyancestors`

Otherwise, you can download the source package and then execute:
Alternatively, you can download the source package and then execute:

`python3 setup.py install`
`python3 -m pip install getmyancestors/`

How to use
==========
Expand Down
40 changes: 38 additions & 2 deletions getmyancestors/classes/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,51 @@ def get_contributors(self):
temp = set()
url = "/platform/tree/persons/%s/changes" % self.fid
data = self.tree.fs.get_url(url, {"Accept": "application/x-gedcomx-atom+json"})
# To reduce calls to the FamilySearch API, first gather the list of contributor
# names, which map to their agent URI; after all the contributor names have been
# gathered, then get the contributor information (email, phone) for each unique one
d = {} # dictionary to store contributor names and corresponding agent URIs
agent_data = ""
agent_url = ""
if data:
for entries in data["entries"]:
for contributors in entries["contributors"]:
d[contributors["name"]] = contributors["uri"].replace("https://www.familysearch.org","")
temp.add(contributors["name"])
if temp:
text = "=== %s ===\n%s" % (
text = "=== %s ===\n" % (
self.tree.fs._("Contributors"),
"\n".join(sorted(temp)),
)
for name in sorted(temp):
text += name
agent_url = d[name]
# I don't know why, but this get_url() request didn't work
# with {"Accept": "application/x-gedcomx-atom+json"}, but
# it did work with the default headers.
agent_data = self.tree.fs.get_url(agent_url)
# If the contributor has a display name that is different than the username, add it in parentheses
try:
display_name = ""
if (agent_data["agents"][0]["names"]):
for n in agent_data["agents"][0]["names"]:
display_name += n["value"] + " "
display_name = display_name[:-1] # Remove trailing space after final name
if (display_name != name):
text += " ("+display_name+")"
except:
pass
# If the contributor has an email address, add that
try:
text += agent_data["agents"][0]["emails"][0]["resource"].replace("mailto:"," ")
except:
pass
# If the contributor has a phone number, add that
try:
text += agent_data["agents"][0]["phones"][0]["resource"].replace("tel:"," ")
except:
pass
text += "\n"

for n in self.tree.notes:
if n.text == text:
self.notes.add(n)
Expand Down