]> Nutra Git (v1) - gamesguru/getmyancestors.git/commitdiff
Option -c : check LDS account
authorlinek <benoitfontaine.ba@gmail.com>
Tue, 18 Jul 2017 18:40:57 +0000 (20:40 +0200)
committerlinek <benoitfontaine.ba@gmail.com>
Tue, 18 Jul 2017 18:40:57 +0000 (20:40 +0200)
README.md
getmyancestors.py

index 6e034ff12e0606a9cf6926df0e3a2f188901857b..96d262bd3d7d9d353fb5045e8972409f3697b580 100644 (file)
--- 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
index df7c243c27bbf5df2c971400067ef27a7df41ede..f661e5d6974d562951746c0ae3103937806088b6 100755 (executable)
@@ -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='<INT>', type=int, default=4, help='Number of generations to ascend [4]')
     parser.add_argument('-d', metavar='<INT>', 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='<INT>', 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: