]> Nutra Git (v2) - gamesguru/getmyancestors.git/commitdiff
Added exclude list parameter to be able to exclude people from the generation
authorBarnabas Sudy <barnabas.sudy@gmail.com>
Sun, 7 Jul 2024 08:41:27 +0000 (10:41 +0200)
committerBarnabas Sudy <barnabas.sudy@gmail.com>
Sun, 7 Jul 2024 08:41:27 +0000 (10:41 +0200)
getmyancestors/classes/session.py
getmyancestors/classes/tree.py
getmyancestors/getmyancestors.py
requirements.txt

index 5fb2700ad7ae8d1e8c2c1b673057314567b9b95e..dba41d59524c20b531c8badcaef78ac418401dd9 100644 (file)
@@ -1,6 +1,7 @@
 # global imports
 import sys
 import time
+from urllib.parse import urlparse, parse_qs
 
 import requests
 from fake_useragent import UserAgent
@@ -78,6 +79,37 @@ class Session(requests.Session):
                 self.write_log("Downloading: " + url)
                 res = self.get(url, headers=self.headers)
                 res.raise_for_status()
+
+                url = f"https://ident.familysearch.org/cis-web/oauth2/v3/authorization?response_type=code&scope=openid profile email qualifies_for_affiliate_account country&client_id=a02j000000KTRjpAAH&redirect_uri=https://misbach.github.io/fs-auth/index_raw.html&username={self.username}"
+                self.write_log("Downloading: " + url)
+                response = self.get(url, allow_redirects=False, headers=self.headers)
+                location = response.headers["location"]
+                code = parse_qs(urlparse(location).query).get("code")
+                url = "https://ident.familysearch.org/cis-web/oauth2/v3/token"
+                self.write_log("Downloading: " + url)
+                res = self.post(
+                    url,
+                    data={
+                        "grant_type": "authorization_code",
+                        "client_id": "a02j000000KTRjpAAH",
+                        "code": code,
+                        "redirect_uri": "https://misbach.github.io/fs-auth/index_raw.html",
+                    },
+                    headers=self.headers,
+                )
+
+                try:
+                    data = res.json()
+                except ValueError:
+                    self.write_log("Invalid auth request")
+                    continue
+
+                if "access_token" not in data:
+                    self.write_log(res.text)
+                    continue
+                access_token = data["access_token"]
+                self.headers.update({"Authorization": f"Bearer {access_token}"})
+
             except requests.exceptions.ReadTimeout:
                 self.write_log("Read timed out")
                 continue
@@ -111,7 +143,7 @@ class Session(requests.Session):
             try:
                 self.write_log("Downloading: " + url)
                 r = self.get(
-                    "https://familysearch.org" + url,
+                    "https://api.familysearch.org" + url,
                     timeout=self.timeout,
                     headers=headers,
                 )
index 8ad2eede1ec05cdf75955302359b97d11a6df566..23a713e61eb1ca0237b8dc5813c048ee3543c71c 100644 (file)
@@ -634,7 +634,7 @@ class Tree:
     :param fs: a Session object
     """
 
-    def __init__(self, fs=None):
+    def __init__(self, fs=None, exclude=None):
         self.fs = fs
         self.indi = dict()
         self.fam = dict()
@@ -642,14 +642,23 @@ class Tree:
         self.sources = dict()
         self.places = dict()
         self.display_name = self.lang = None
+        self.exclude = exclude or []
         if fs:
             self.display_name = fs.display_name
             self.lang = babelfish.Language.fromalpha2(fs.lang).name
 
-    def add_indis(self, fids):
+    def add_indis(self, fids_in):
         """add individuals to the family tree
         :param fids: an iterable of fid
         """
+        fids = []
+        for fid in fids_in:
+            if fid not in self.exclude:
+                fids.append(fid)
+            else:
+                print(
+                    "Excluding %s from the family tree" % fid, file=sys.stderr
+                )
 
         async def add_datas(loop, data):
             futures = set()
index 7fbbdf3f633a4e57eea8e34b53e1f6da311dc656..68baaa8dd31f3765564b43d179fd7b6d44f699bb 100644 (file)
@@ -35,6 +35,14 @@ def main():
         type=str,
         help="List of individual FamilySearch IDs for whom to retrieve ancestors",
     )
+    parser.add_argument(
+        "-e",
+        "--exclude",
+        metavar="<STR>",
+        nargs="+",
+        type=str,
+        help="List of individual FamilySearch IDs to exclude from the tree",
+    )
     parser.add_argument(
         "-a",
         "--ascend",
@@ -132,6 +140,10 @@ def main():
         for fid in args.individuals:
             if not re.match(r"[A-Z0-9]{4}-[A-Z0-9]{3}", fid):
                 sys.exit("Invalid FamilySearch ID: " + fid)
+    if args.exclude:
+        for fid in args.exclude:
+            if not re.match(r"[A-Z0-9]{4}-[A-Z0-9]{3}", fid):
+                sys.exit("Invalid FamilySearch ID: " + fid)
 
     args.username = (
         args.username if args.username else input("Enter FamilySearch username: ")
@@ -177,7 +189,7 @@ def main():
     if not fs.logged:
         sys.exit(2)
     _ = fs._
-    tree = Tree(fs)
+    tree = Tree(fs, exclude=args.exclude)
 
     # check LDS account
     if args.get_ordinances:
index 30668f8d39573d548de912033b7dff8bab531f2a..c2d23a8680cc1beb8a7b70a456ee87c843604c9b 100644 (file)
@@ -2,3 +2,4 @@ babelfish==0.6.0
 diskcache==5.2.1
 requests==2.31.0
 fake-useragent==1.2.1
+setuptools==70.1.0
\ No newline at end of file