]> git.mxchange.org Git - fba.git/blobdiff - fetch_blocks.py
Continued:
[fba.git] / fetch_blocks.py
index 612b84f985fcf9ab521591fd8926b1bb61d2f129..d2649c06d6afef91f55e81adeeecb19e4097f48b 100755 (executable)
@@ -78,6 +78,7 @@ for blocker, software, origin, nodeinfo_url in rows:
                         print("WARNING: block_level is now empty!")
                         continue
 
+                    # DEBUG: print(f"DEBUG: Checking {len(blocks)} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...")
                     for blocked in blocks:
                         # DEBUG: print("DEBUG: BEFORE blocked:", blocked)
                         blocked = fba.tidyup(blocked)
@@ -133,7 +134,7 @@ for blocker, software, origin, nodeinfo_url in rows:
                                         "reason" : None
                                     })
                         else:
-                            # DEBUG: print("DEBUG: Updating last_seen:", blocker, blocked, block_level)
+                            print(f"DEBUG: Updating block last seen for blocker='{blocker}',blocked='{blocked}' ...")
                             fba.update_last_seen(blocker, blocked, block_level)
 
             fba.connection.commit()
@@ -155,6 +156,7 @@ for blocker, software, origin, nodeinfo_url in rows:
                         print("WARNING: block_level is now empty!")
                         continue
 
+                    # DEBUG: print(f"DEBUG: Checking {len(info.items())} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...")
                     for blocked, reason in info.items():
                         # DEBUG: print("DEBUG: BEFORE blocked:", blocked)
                         blocked = fba.tidyup(blocked)
@@ -239,12 +241,16 @@ for blocker, software, origin, nodeinfo_url in rows:
 
                     # DEBUG: print("DEBUG: severity,domain,hash,comment:", block['severity'], block['domain'], block['digest'], block['comment'])
                     if block['severity'] == 'suspend':
+                        # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...")
                         json['reject'].append(entry)
                     elif block['severity'] == 'silence':
+                        # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...")
                         json['followers_only'].append(entry)
                     elif block['severity'] == 'reject_media':
+                        # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...")
                         json['media_removal'].append(entry)
                     elif block['severity'] == 'reject_reports':
+                        # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...")
                         json['report_removal'].append(entry)
                     else:
                         print("WARNING: Unknown severity:", block['severity'], block['domain'])
@@ -261,6 +267,7 @@ for blocker, software, origin, nodeinfo_url in rows:
                     print("WARNING: block_level is empty, blocker:", blocker)
                     continue
 
+                # DEBUG: print(f"DEBUG: Checking {len(blocks)} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...")
                 for instance in blocks:
                     blocked, blocked_hash, reason = instance.values()
                     # DEBUG: print("DEBUG: blocked,hash,reason:", blocked, blocked_hash, reason)
@@ -308,18 +315,21 @@ for blocker, software, origin, nodeinfo_url in rows:
                         # DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker)
                         fba.add_instance(blocked, blocker, origin, nodeinfo_url)
 
+                    blocking = blocked if blocked.count("*") <= 1 else blocked_hash
+                    # DEBUG: print(f"DEBUG: blocking='{blocking}',blocked='{blocked}',blocked_hash='{blocked_hash}'")
+
                     fba.cursor.execute(
                         "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
                         (
                             blocker,
-                            blocked if blocked.count("*") <= 1 else blocked_hash,
+                            blocking,
                             block_level
                         ),
                     )
 
                     if fba.cursor.fetchone() == None:
                         # DEBUG: print("DEBUG: Blocking:", blocker, blocked, block_level)
-                        fba.block_instance(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, reason, block_level)
+                        fba.block_instance(blocker, blocking, reason, block_level)
 
                         if block_level == "reject":
                             blockdict.append(
@@ -328,11 +338,9 @@ for blocker, software, origin, nodeinfo_url in rows:
                                     "reason" : reason
                                 })
                     else:
-                        fba.update_last_seen(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level)
-
-                    if reason != "":
-                        # 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)
+                        # DEBUG: print(f"DEBUG: Updating block last seen and reason for blocker='{blocker}',blocking='{blocking}' ...")
+                        fba.update_last_seen(blocker, blocking, block_level)
+                        fba.update_block_reason(reason, blocker, blocking, block_level)
 
             fba.connection.commit()
         except Exception as e:
@@ -360,6 +368,7 @@ for blocker, software, origin, nodeinfo_url in rows:
                     print("WARNING: block_level is empty, blocker:", blocker)
                     continue
 
+                # DEBUG: print(f"DEBUG: Checking {len(blocks)} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...")
                 for instance in blocks:
                     blocked, reason = instance.values()
                     # DEBUG: print("DEBUG: BEFORE blocked:", blocked)
@@ -415,8 +424,8 @@ for blocker, software, origin, nodeinfo_url in rows:
                         fba.add_instance(blocked, blocker, origin, nodeinfo_url)
 
                     fba.cursor.execute(
-                        "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? LIMIT 1",
-                        (blocker, blocked),
+                        "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
+                        (blocker, blocked, block_level),
                     )
 
                     if fba.cursor.fetchone() == None:
@@ -429,10 +438,8 @@ for blocker, software, origin, nodeinfo_url in rows:
                                     "reason" : reason
                                 })
                     else:
+                        print(f"DEBUG: Updating block last seen and reason for blocker='{blocker}',blocked='{blocked}' ...")
                         fba.update_last_seen(blocker, blocked, block_level)
-
-                    if reason != '':
-                        # DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason)
                         fba.update_block_reason(reason, blocker, blocked, block_level)
 
             fba.connection.commit()
@@ -507,6 +514,7 @@ for blocker, software, origin, nodeinfo_url in rows:
                                 "reason" : None
                             })
                     else:
+                        print(f"DEBUG: Updating block last seen for blocker='{blocker}',blocked='{blocked}' ...")
                         fba.update_last_seen(blocker, blocked, "reject")
 
                     if "public_comment" in peer: