]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 24 May 2023 10:34:43 +0000 (12:34 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 24 May 2023 10:34:43 +0000 (12:34 +0200)
- also including 'follower', not only 'following'

fba.py

diff --git a/fba.py b/fba.py
index e8885a9829f880f4fccfccc9179d34be49f92072..6806d5e5e2ee6ed7a350eacdd3e35408caa6db15 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -213,42 +213,43 @@ def get_peers(domain: str, software: str) -> list:
         # NOISY-DEBUG: print(f"DEBUG: domain='{domain}' is a PeerTube, fetching JSON ...")
 
         start = 0
-        while True:
-            try:
-                res = reqto.get(f"https://{domain}/api/v1/server/followers?start={start}&count=100", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
-
-                # NOISY-DEBUG: print(f"DEBUG: res.ok={res.ok},res.json[]={type(res.json())}")
-                if res.ok and isinstance(res.json(), dict):
-                    # NOISY-DEBUG: uccess, res.json():", len(res.json()))
-                    json = res.json()
-                    if start == 0:
-                        # NOISY-DEBUG: print(f"DEBUG: Setting get_peers_url for '{domain}' ...")
-                        nodeinfos["get_peers_url"][domain] = f"https://{domain}/api/v1/server/followers?start={start}&count=100"
-
-                    if "data" in json:
-                        # NOISY-DEBUG: print(f"DEBUG: Found {len(json['data'])} record(s).")
-                        for record in json["data"]:
-                            # NOISY-DEBUG: print(f"DEBUG: record()={len(record)}")
-                            if "follower" in record and "host" in record["follower"]:
-                                # NOISY-DEBUG: print(f"DEBUG: Found host={record['follower']['host']}, adding ...")
-                                peers.append(record["follower"]["host"])
-                            else:
-                                print(f"WARNING: record from '{domain}' has no 'follower' or 'host' record: {record}")
-
-                        if len(json["data"]) < 100:
-                            # NOISY-DEBUG: print("DEBUG: Reached end of JSON response:", domain)
-                            break
-
-                    # Continue with next row
-                    start = start + 100
+        for mode in ["followers", "following"]:
+            print(f"DEBUG: domain='{domain}',mode='{mode}'")
+            while True:
+                try:
+                    res = reqto.get(f"https://{domain}/api/v1/server/{mode}?start={start}&count=100", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
+
+                    # NOISY-DEBUG: print(f"DEBUG: res.ok={res.ok},res.json[]={type(res.json())}")
+                    if res.ok and isinstance(res.json(), dict):
+                        # NOISY-DEBUG: uccess, res.json():", len(res.json()))
+                        json = res.json()
+
+                        if "data" in json:
+                            # NOISY-DEBUG: print(f"DEBUG: Found {len(json['data'])} record(s).")
+                            for record in json["data"]:
+                                # NOISY-DEBUG: print(f"DEBUG: record()={len(record)}")
+                                if "follower" in record and "host" in record["follower"]:
+                                    # NOISY-DEBUG: print(f"DEBUG: Found host={record['follower']['host']}, adding ...")
+                                    peers.append(record["follower"]["host"])
+                                else:
+                                    print(f"WARNING: record from '{domain}' has no 'follower' or 'host' record: {record}")
+
+                            if len(json["data"]) < 100:
+                                # NOISY-DEBUG: print("DEBUG: Reached end of JSON response:", domain)
+                                break
+
+                        # Continue with next row
+                        start = start + 100
 
             except BaseException as e:
                 print("WARNING: Exception during fetching JSON:", domain, e)
 
-        update_last_nodeinfo(domain)
+            update_last_nodeinfo(domain)
 
-        # NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers))
-        return peers
+            # NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers))
+            return peers
+
+    # NOISY-DEBUG: print(f"DEBUG: Fetching '{get_peers_url}' from '{domain}' ...")
     try:
         res = reqto.get(f"https://{domain}{get_peers_url}", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))