diff --git a/README.md b/README.md index 7e14ee3..c15d0cf 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 ========== diff --git a/getmyancestors/classes/tree.py b/getmyancestors/classes/tree.py index 4bea414..3d0ba4b 100644 --- a/getmyancestors/classes/tree.py +++ b/getmyancestors/classes/tree.py @@ -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)