]> git.mxchange.org Git - fba.git/commitdiff
Very noisy debug lines
authorRoland Häder <roland@mxchange.org>
Thu, 18 May 2023 05:00:57 +0000 (07:00 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 18 May 2023 05:07:33 +0000 (07:07 +0200)
fba.py
fetch_blocks.py
fetch_instances.py

diff --git a/fba.py b/fba.py
index f0c6f6b8bd3e15dff8f55a67093932d27dbb888e..188fb70e0b76aaf8d993df56019c3a3cb0d3f3d5 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -219,7 +219,7 @@ def get_friendica_blocks(domain: str) -> dict:
 
     # Prevents exceptions:
     if blocklist is None:
-        print("Instance has no block list:", domain)
+        # NOISY-DEBUG: print("DEBUG: Instance has no block list:", domain)
         return {}
 
     for line in blocklist.find("table").find_all("tr")[1:]:
index 7e148f477cb5e50831a7edcfb8d43a03b2e8a237..7cc6fda20a9a6af474f9f009584af8d6820767d4 100644 (file)
@@ -10,7 +10,7 @@ fba.c.execute(
 )
 
 for blocker, software in fba.c.fetchall():
-    print("DEBUG: blocker,software:", blocker, software)
+    # NOISY-DEBUG: print("DEBUG: blocker,software:", blocker, software)
     blockdict = []
     blocker = fba.tidyup(blocker)
     if software == "pleroma":
@@ -26,9 +26,9 @@ for blocker, software in fba.c.fetchall():
                     **{"quarantined_instances": federation["quarantined_instances"]}}
                 ).items():
                     for blocked in blocks:
-                        print("DEBUG: BEFORE blocked:", blocked)
+                        # NOISY-DEBUG: print("DEBUG: BEFORE blocked:", blocked)
                         blocked = fba.tidyup(blocked)
-                        print("DEBUG: AFTER blocked:", blocked)
+                        # NOISY-DEBUG: print("DEBUG: AFTER blocked:", blocked)
 
                         if blocked == "":
                             print("WARNING: blocked is empty after fba.tidyup():", blocker, block_level)
@@ -40,17 +40,17 @@ for blocker, software in fba.c.fetchall():
                                 "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),)
                             )
                             searchres = fba.c.fetchone()
-                            print("DEBUG: searchres[]:", type(searchres))
+                            # NOISY-DEBUG: print("DEBUG: searchres[]:", type(searchres))
                             if searchres != None:
                                 blocked = searchres[0]
 
-                        print("DEBUG: Looking up instance by domain:", blocked)
+                        # NOISY-DEBUG: print("DEBUG: Looking up instance by domain:", blocked)
                         fba.c.execute(
                             "SELECT domain FROM instances WHERE domain = ?", (blocked,)
                         )
 
                         if fba.c.fetchone() == None:
-                            print("DEBUG: Domain wasn't found, adding:", blocked)
+                            # NOISY-DEBUG: print("DEBUG: Domain wasn't found, adding:", blocked)
                             fba.add_instance(blocked)
 
                         timestamp = int(time.time())
@@ -79,18 +79,18 @@ for blocker, software in fba.c.fetchall():
 
             # Reasons
             if "mrf_simple_info" in federation:
-                print("DEBUG: Found mrf_simple_info:", blocker)
+                # NOISY-DEBUG: print("DEBUG: Found mrf_simple_info:", blocker)
                 for block_level, info in (
                     {**federation["mrf_simple_info"],
                     **(federation["quarantined_instances_info"]
                     if "quarantined_instances_info" in federation
                     else {})}
                 ).items():
-                    print("DEBUG: block_level, info.items():", block_level, len(info.items()))
+                    # NOISY-DEBUG: print("DEBUG: block_level, info.items():", block_level, len(info.items()))
                     for blocked, reason in info.items():
-                        print("DEBUG: BEFORE blocked:", blocked)
+                        # NOISY-DEBUG: print("DEBUG: BEFORE blocked:", blocked)
                         blocked = fba.tidyup(blocked)
-                        print("DEBUG: AFTER blocked:", blocked)
+                        # NOISY-DEBUG: print("DEBUG: AFTER blocked:", blocked)
 
                         if blocked == "":
                             print("WARNING: blocked is empty after fba.tidyup():", blocker, block_level)
@@ -106,12 +106,12 @@ for blocker, software in fba.c.fetchall():
                             if searchres != None:
                                 blocked = searchres[0]
 
-                        print("DEBUG: Updating block reason:", blocker, blocked, reason["reason"])
+                        # NOISY-DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason["reason"])
                         fba.update_block_reason(reason["reason"], blocker, blocked, block_level)
 
                         for entry in blockdict:
                             if entry["blocked"] == blocked:
-                                print("DEBUG: Updating entry reason:", blocked)
+                                # NOISY-DEBUG: print("DEBUG: Updating entry reason:", blocked)
                                 entry["reason"] = reason["reason"]
 
             fba.conn.commit()
@@ -130,29 +130,29 @@ for blocker, software in fba.c.fetchall():
                 }
 
                 # handling CSRF, I've saw at least one server requiring it to access the endpoint
-                print("DEBUG: Fetching meta:", blocker)
+                # NOISY-DEBUG: print("DEBUG: Fetching meta:", blocker)
                 meta = bs4.BeautifulSoup(
                     reqto.get(f"https://{blocker}/about", headers=fba.headers, timeout=5).text,
                     "html.parser",
                 )
                 try:
                     csrf = meta.find("meta", attrs={"name": "csrf-token"})["content"]
-                    print("DEBUG: Adding CSRF token:", blocker, csrf)
+                    # NOISY-DEBUG: print("DEBUG: Adding CSRF token:", blocker, csrf)
                     reqheaders = {**fba.headers, **{"x-csrf-token": csrf}}
                 except:
-                    print("DEBUG: No CSRF token found, using normal headers:", blocker)
+                    # NOISY-DEBUG: print("DEBUG: No CSRF token found, using normal headers:", blocker)
                     reqheaders = fba.headers
 
-                print("DEBUG: Quering API domain_blocks:", blocker)
+                # NOISY-DEBUG: print("DEBUG: Quering API domain_blocks:", blocker)
                 blocks = reqto.get(
                     f"https://{blocker}/api/v1/instance/domain_blocks", headers=reqheaders, timeout=5
                 ).json()
 
-                print("DEBUG: blocks():", len(blocks))
+                # NOISY-DEBUG: print("DEBUG: blocks():", len(blocks))
                 for block in blocks:
                     entry = {'domain': block['domain'], 'hash': block['digest'], 'reason': block['comment']}
 
-                    print("DEBUG: severity,domain,hash,comment:", block['severity'], block['domain'], block['digest'], block['comment'])
+                    # NOISY-DEBUG: print("DEBUG: severity,domain,hash,comment:", block['severity'], block['domain'], block['digest'], block['comment'])
                     if block['severity'] == 'suspend':
                         json['reject'].append(entry)
                     elif block['severity'] == 'silence':
@@ -164,18 +164,18 @@ for blocker, software in fba.c.fetchall():
                     else:
                         print("WARNING: Unknown severity:", block['severity'], block['domain'])
             except:
-                print("DEBUG: Failed, Trying mastodon-specific fetches:", blocker)
+                # NOISY-DEBUG: print("DEBUG: Failed, Trying mastodon-specific fetches:", blocker)
                 json = fba.get_mastodon_blocks(blocker)
 
-            print("DEBUG: json.items():", blocker, len(json.items()))
+            # NOISY-DEBUG: print("DEBUG: json.items():", blocker, len(json.items()))
             for block_level, blocks in json.items():
-                print("DEBUG: blocker,block_level,blocks():", blocker, block_level, len(blocks))
+                # NOISY-DEBUG: print("DEBUG: blocker,block_level,blocks():", blocker, block_level, len(blocks))
                 for instance in blocks:
                     blocked, blocked_hash, reason = instance.values()
-                    print("DEBUG: blocked,hash,reason:", blocked, blocked_hash, reason)
+                    # NOISY-DEBUG: print("DEBUG: blocked,hash,reason:", blocked, blocked_hash, reason)
 
                     blocked = fba.tidyup(blocked)
-                    print("DEBUG: blocked:", blocked)
+                    # NOISY-DEBUG: print("DEBUG: blocked:", blocked)
 
                     if blocked.count("*") < 1:
                         # No obsfucation for this instance
@@ -184,7 +184,7 @@ for blocker, software in fba.c.fetchall():
                         )
 
                         if fba.c.fetchone() == None:
-                            print("DEBUG: Hash wasn't found, adding:", blocked)
+                            # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked)
                             fba.add_instance(blocked)
                     else:
                         # Doing the hash search for instance names as well to tidy up DB
@@ -194,7 +194,7 @@ for blocker, software in fba.c.fetchall():
                         searchres = fba.c.fetchone()
 
                         if searchres != None:
-                            print("DEBUG: Updating domain: ", searchres[0])
+                            # NOISY-DEBUG: print("DEBUG: Updating domain: ", searchres[0])
                             blocked = searchres[0]
 
                     timestamp = int(time.time())
@@ -220,7 +220,7 @@ for blocker, software in fba.c.fetchall():
                         fba.update_last_seen(timestamp, blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level)
 
                     if reason != '':
-                        print("DEBUG: Updating block reason:", blocker, blocked, reason)
+                        # NOISY-DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason)
                         fba.update_block_reason(reason, blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level)
 
             fba.conn.commit()
@@ -238,7 +238,7 @@ for blocker, software in fba.c.fetchall():
                     blocked, reason = instance.values()
                     blocked = fba.tidyup(blocked)
 
-                    print("BEFORE-blocked:", blocked)
+                    # NOISY-DEBUG: print("DEBUG: BEFORE-blocked:", blocked)
                     if blocked.count("*") > 0:
                         # Some friendica servers also obscure domains without hash
                         fba.c.execute(
@@ -257,13 +257,13 @@ for blocker, software in fba.c.fetchall():
                         if searchres != None:
                             blocked = searchres[0]
 
-                    print("AFTER-blocked:", blocked)
+                    # NOISY-DEBUG: print("DEBUG: AFTER-blocked:", blocked)
                     fba.c.execute(
                         "SELECT domain FROM instances WHERE domain = ?", (blocked,)
                     )
 
                     if fba.c.fetchone() == None:
-                        print("DEBUG: Hash wasn't found, adding:", blocked)
+                        # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked)
                         fba.add_instance(blocked)
 
                     timestamp = int(time.time())
@@ -284,7 +284,7 @@ for blocker, software in fba.c.fetchall():
                         fba.update_last_seen(timestamp, blocker, blocked, block_level)
 
                     if reason != '':
-                        print("DEBUG: Updating block reason:", blocker, blocked, reason)
+                        # NOISY-DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason)
                         fba.update_block_reason(reason, blocker, blocked, block_level)
 
             fba.conn.commit()
@@ -302,13 +302,13 @@ for blocker, software in fba.c.fetchall():
                 print("WARNING: No valid response:", blocker);
             else:
                 for peer in federation:
-                    print("DEBUG: peer(),[]:", len(peer), type(peer))
+                    # NOISY-DEBUG: print("DEBUG: peer(),[]:", len(peer), type(peer))
                     if (isinstance(peer, str) and peer == "error"):
                         print("WARNING: Cannot continue, maybe authentication required?", blocker)
                         break
 
                     blocked = peer["domain"].lower()
-                    print("DEBUG: blocked:", blocked)
+                    # NOISY-DEBUG: print("DEBUG: blocked:", blocked)
 
                     if blocked.count("*") > 0:
                         # GTS does not have hashes for obscured domains, so we have to guess it
@@ -325,7 +325,7 @@ for blocker, software in fba.c.fetchall():
                     )
 
                     if fba.c.fetchone() == None:
-                        print("DEBUG: Hash wasn't found, adding:", blocked)
+                        # NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked)
                         fba.add_instance(blocked)
 
                     fba.c.execute(
@@ -351,7 +351,7 @@ for blocker, software in fba.c.fetchall():
 
                     if "public_comment" in peer:
                         reason = peer["public_comment"]
-                        print("DEBUG: Updating block reason:", blocker, blocked, reason)
+                        # NOISY-DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason)
                         fba.update_block_reason(reason, blocker, blocked, "reject")
 
                         for entry in blockdict:
index 207c5caf1bf119581b3be03cca4318f6349119e8..5527f9c7e82934c1ba7f2a6a692ff76687e5ce1c 100644 (file)
@@ -24,10 +24,10 @@ for instance in peerlist:
             blacklisted = True
 
     if blacklisted:
-        print("DEBUG: domain is blacklisted:", domain)
+        print("WARNING: domain is blacklisted:", domain)
         continue
 
-    print("DEBUG: Handling instance:", instance)
+    print("INFO: Handling instance:", instance)
     try:
         fba.c.execute(
             "SELECT domain FROM instances WHERE domain = ? LIMIT 1", (instance,)