From d21ef16bcb57dee814ad77e5b2cdf650d27f9214 Mon Sep 17 00:00:00 2001 From: linek Date: Tue, 18 Jul 2017 20:40:57 +0200 Subject: [PATCH] Option -c : check LDS account --- README.md | 2 +- getmyancestors.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6e034ff..96d262b 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Download six generations of ancestors for individuals L4S5-9X4 and LHWG-18F incl python3 getmyancestors.py -a 6 -d 2 -m -u username -p password -i L4S5-9X4 LHWG-18F -o out.ged ``` -Download four generations of ancestors for individual LF7T-Y4C including LDS ordinances +Download four generations of ancestors for individual LF7T-Y4C including LDS ordinances (need LDS account) ``` python3 getmyancestors.py -c -u username -p password -i LF7T-Y4C -o out.ged diff --git a/getmyancestors.py b/getmyancestors.py index df7c243..f661e5d 100755 --- a/getmyancestors.py +++ b/getmyancestors.py @@ -175,7 +175,7 @@ class Session: if self.verbose: self.logfile.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + ']: Downloading: ' + url + '\n') # r = requests.get(url, cookies = { 's_vi': self.s_vi, 'fssessionid' : self.fssessionid }, timeout = self.timeout) - r = requests.get(url, cookies={'fssessionid': self.fssessionid}, timeout=self.timeout) + fr = requests.get(url, cookies={'fssessionid': self.fssessionid}, timeout=self.timeout) except requests.exceptions.ReadTimeout: if self.verbose: self.logfile.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + ']: Read timed out\n') @@ -186,20 +186,23 @@ class Session: time.sleep(self.timeout) continue if self.verbose: - self.logfile.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + ']: Status code: ' + str(r.status_code) + '\n') - if r.status_code == 204 or r.status_code == 410: + self.logfile.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + ']: Status code: ' + str(fr.status_code) + '\n') + if fr.status_code == 204 or fr.status_code == 410: return None - if r.status_code == 401: + if fr.status_code == 401: self.login() continue try: - r.raise_for_status() + fr.raise_for_status() except requests.exceptions.HTTPError: if self.verbose: self.logfile.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + ']: HTTPError\n') + if 'message' in fr.json()['errors'][0] and fr.json()['errors'][0]['message'] == u'Unable to get ordinances.': + self.logfile.write('Unable to get ordinances. Try without option -c.\n') + exit() time.sleep(self.timeout) continue - return r.json() + return fr.json() # retrieve FamilySearch current user ID def get_userid(self): @@ -789,7 +792,7 @@ if __name__ == '__main__': parser.add_argument('-a', metavar='', type=int, default=4, help='Number of generations to ascend [4]') parser.add_argument('-d', metavar='', type=int, default=0, help='Number of generations to descend [0]') parser.add_argument('-m', action="store_true", default=False, help='Add spouses and couples information [False]') - parser.add_argument('-c', action="store_true", default=False, help='Add LDS ordinances [False]') + parser.add_argument('-c', action="store_true", default=False, help='Add LDS ordinances (need LDS account) [False]') parser.add_argument("-v", action="store_true", default=False, help="Increase output verbosity [False]") parser.add_argument('-t', metavar='', type=int, default=60, help='Timeout in seconds [60]') try: @@ -815,6 +818,10 @@ if __name__ == '__main__': fs = Session(username, password, args.v, args.l, args.t) tree = Tree(fs) + # check LDS account + if args.c: + fs.get_url('https://familysearch.org/platform/tree/persons/' + fs.get_userid() + '/ordinances.json') + # add list of starting individuals to the family tree todo = set(args.i if args.i else [fs.get_userid()]) for fid in todo: -- 2.52.0