]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 13 Jun 2023 02:18:29 +0000 (04:18 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 13 Jun 2023 02:20:23 +0000 (04:20 +0200)
- removed some wrapper functions
- update instance data even when the connection didn't work or some error
  status code (>= 400) came

fba/commands.py
fba/federation.py
fba/models/instances.py
fba/networks/friendica.py
fba/networks/lemmy.py
fba/networks/misskey.py
fba/networks/peertube.py

index 63c185f08d761c5221c4fd5187f058cdc2c9d862..7a64081fd43866c9b95626efce0d8fd6092856ca 100644 (file)
@@ -169,7 +169,7 @@ def fetch_blocks(args: argparse.Namespace):
             continue
 
         # DEBUG: print(f"DEBUG: blocker='{blocker}'")
-        instances.update_last_blocked(blocker)
+        instances.set_data("last_blocked", blocker, time.time())
 
         if software == "pleroma":
             print(f"INFO: blocker='{blocker}',software='{software}'")
@@ -267,6 +267,10 @@ def fetch_blocks(args: argparse.Namespace):
         else:
             print("WARNING: Unknown software:", blocker, software)
 
+        if instances.has_pending(blocker):
+            # DEBUG: print(f"DEBUG: Invoking instances.update_data({blocker}) ...")
+            instances.update_data(blocker)
+
         if config.get("bot_enabled") and len(blockdict) > 0:
             network.send_bot_post(blocker, blockdict)
 
index 9e0922d94c2f888f0751b71845f5e26ad8bb7334..118c45dd4d8de200527e90fd15902a8f9f5b46a4 100644 (file)
@@ -14,6 +14,7 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 import bs4
+import time
 import validators
 
 from fba import blacklist
@@ -54,7 +55,7 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path:
         raise ValueError(f"Parameter origin[]='{type(origin)}' is not 'str'")
     elif software is None:
         # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
-        instances.update_last_instance_fetch(domain)
+        instances.set_data("last_instance_fetch", domain, time.time())
 
         # DEBUG: print(f"DEBUG: software for domain='{domain}' is not set, determining ...")
         software = determine_software(domain, path)
@@ -72,6 +73,9 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path:
         # DEBUG: print("DEBUG: Adding new domain:", domain, origin)
         instances.add(domain, origin, command, path)
 
+    # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
+    instances.set_data("last_instance_fetch", domain, time.time())
+
     # DEBUG: print("DEBUG: Fetching instances for domain:", domain, software)
     peerlist = fetch_peers(domain, software)
 
@@ -184,9 +188,6 @@ def fetch_peers(domain: str, software: str) -> list:
     # DEBUG: print(f"DEBUG: Adding '{len(peers)}' for domain='{domain}'")
     instances.set_data("total_peers", domain, len(peers))
 
-    # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
-    instances.update_last_instance_fetch(domain)
-
     # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
     return peers
 
index 99e61ec65f292f42bba92cf9cf94ec720659e4c5..91c4722554c0805a08bf5edd642d76022fffa27b 100644 (file)
@@ -146,38 +146,6 @@ def update_data(domain: str):
 
     # DEBUG: print("DEBUG: EXIT!")
 
-def update_last_instance_fetch(domain: str):
-    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-
-    # DEBUG: print("DEBUG: Updating last_instance_fetch for domain:", domain)
-    set_data("last_instance_fetch", domain, time.time())
-
-    # Running pending updated
-    # DEBUG: print(f"DEBUG: Invoking update_data({domain}) ...")
-    update_data(domain)
-
-    # DEBUG: print("DEBUG: EXIT!")
-
-def update_last_blocked(domain: str):
-    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-
-    # DEBUG: print("DEBUG: Updating last_blocked for domain", domain)
-    set_data("last_blocked", domain, time.time())
-
-    # Running pending updated
-    # DEBUG: print(f"DEBUG: Invoking update_data({domain}) ...")
-    update_data(domain)
-
-    # DEBUG: print("DEBUG: EXIT!")
-
 def add(domain: str, origin: str, command: str, path: str = None):
     # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',command='{command}',path='{path}' - CALLED!")
     if not isinstance(domain, str):
index 6941dab25f857429bb0b99949900b8840007c712..aef3f23d85a2457d140ec808f245f694a93fc3e3 100644 (file)
@@ -50,10 +50,6 @@ def fetch_blocks(domain: str) -> dict:
     except network.exceptions as exception:
         print(f"WARNING: Exception '{type(exception)}' during fetching instances (friendica) from domain='{domain}'")
         instances.update_last_error(domain, exception)
-
-        if instances.has_pending(domain):
-            instances.update_data(domain)
-
         return dict()
 
     # Prevents exceptions:
index 8a0a9620b592a75f4d7c0aaff35b7f33c05a45e6..df6b6bccc62dbe9255b2a16ba9289e2c4e75851f 100644 (file)
@@ -67,8 +67,5 @@ def fetch_peers(domain: str) -> list:
     # DEBUG: print(f"DEBUG: Adding '{len(peers)}' for domain='{domain}'")
     instances.set_data("total_peers", domain, len(peers))
 
-    # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
-    instances.update_last_instance_fetch(domain)
-
     # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
     return peers
index 1dedde73bd020e767365f613c7047a0a3f0d241a..e1e7360433e9ca11cf3922eae4b9d90b6575691c 100644 (file)
@@ -119,9 +119,6 @@ def fetch_peers(domain: str) -> list:
     # DEBUG: print(f"DEBUG: Adding '{len(peers)}' for domain='{domain}'")
     instances.set_data("total_peers", domain, len(peers))
 
-    # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
-    instances.update_last_instance_fetch(domain)
-
     # DEBUG: print(f"DEBUG: Returning peers[]='{type(peers)}'")
     return peers
 
@@ -286,9 +283,6 @@ def fetch_blocks(domain: str) -> dict:
             offset = 0
             break
 
-    # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
-    instances.update_last_instance_fetch(domain)
-
     # DEBUG: print(f"DEBUG: Returning for domain='{domain}',blocked()={len(blocklist['blocked'])},suspended()={len(blocklist['suspended'])}")
     return {
         "reject"        : blocklist["blocked"],
index 793fb457786a43a67ad3dffcae4771792bed9bba..b6115d521496f74b45e001ae2f6b667c2af84a2a 100644 (file)
@@ -53,7 +53,7 @@ def fetch_peers(domain: str) -> list:
 
             print(f"DEBUG: data['{type(data)}']='{data}'")
             if "error_message" not in data:
-                print("DEBUG: Success, data[json]:", len(data["json"]))
+                print(f"DEBUG: Success, data[json]()={len(data['json'])}")
                 if "data" in data["json"]:
                     rows = data["json"]["data"]
 
@@ -76,8 +76,5 @@ def fetch_peers(domain: str) -> list:
     print(f"DEBUG: Adding '{len(peers)}' for domain='{domain}'")
     instances.set_data("total_peers", domain, len(peers))
 
-    print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
-    instances.update_last_instance_fetch(domain)
-
     print(f"DEBUG: Returning peers[]='{type(peers)}'")
     return peers