]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 2 Jul 2023 17:26:16 +0000 (19:26 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 2 Jul 2023 17:26:16 +0000 (19:26 +0200)
- added command update_nodeinfo(), please only execute this when you have
  trouble in federation

fba/boot.py
fba/commands.py
fba/helpers/cookies.py
fba/http/network.py

index 157d7a1bbcd096bb8159e2d8b3366fa6b979c895..d04fd95a38c89111ba808f6e4c6828aa79561391 100644 (file)
@@ -182,6 +182,13 @@ def init_parser():
     parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
     parser.add_argument("--all", action="store_true", help="Include also already existing instances, otherwise only new are checked")
 
+    ### Update nodeinfo ###
+    parser = subparser_command.add_parser(
+        "update_nodeinfo",
+        help="Updates nodeinfo for all instances",
+    )
+    parser.set_defaults(command=commands.update_nodeinfo)
+
     logger.debug("EXIT!")
 
 def run_command():
index 938f8c88c2643dc34804cf837aa9e1e6746faa6d..cf88126fdcd3f292a55e8558cdeb8dc64e1d5d5c 100644 (file)
@@ -1370,3 +1370,19 @@ def fetch_fedilist(args: argparse.Namespace) -> int:
 
     logger.debug("Success! - EXIT!")
     return 0
+
+def update_nodeinfo(args: argparse.Namespace) -> int:
+    logger.debug("args[]='%s' - CALLED!", type(args))
+
+    database.cursor.execute("SELECT domain FROM instances WHERE last_nodeinfo < ?", [time.time() - config.get("recheck_block")])
+
+    domains = database.cursor.fetchall()
+
+    logger.info("Checking %d domain(s) ...", len(domains))
+    for row in domains:
+        logger.info("Updating nodeinfo for row[domain]='%s' ...", row["domain"])
+        federation.fetch_nodeinfo(row["domain"])
+        instances.set_last_nodeinfo(row["domain"])
+
+    logger.debug("Success! - EXIT!")
+    return 0
index 3c4fcfde37f55852feda0525c631257d7648e71f..b963a13b694da25783411f49fba433ad985792fc 100644 (file)
@@ -38,8 +38,8 @@ def get_all(domain: str) -> dict:
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
 
-    if not has(domain):
-        raise Exception(f"domain='{domain}' has no cookies stored, maybe invoke store() first?")
+    if domain not in _cookies:
+        return dict()
 
     logger.debug("_cookies[%s]()=%d - EXIT!", domain, len(_cookies[domain]))
     return _cookies[domain]
index 229c474469bab71273959f8d457c4b830f0591b4..c7816c628ecdb0d0efb0afd56c1c7794bfa6b7ca 100644 (file)
@@ -80,16 +80,16 @@ def post_json_api(domain: str, path: str, data: str = "", headers: dict = dict()
             data=data,
             headers={**api_headers, **headers},
             timeout=(config.get("connection_timeout"), config.get("read_timeout")),
-            cookies=cookies.get_all(domain) if cookies.has(domain) else dict(),
+            cookies=cookies.get_all(domain),
             allow_redirects=False
         )
 
         logger.debug("Parsing JSON response from domain='%s',path='%s' ...", domain, path)
         json_reply["json"] = json_helper.from_response(response)
 
-        logger.debug("response.ok='%s',response.status_code=%d,json_reply[]='%s'", response.ok, response.status_code, type(json_reply))
-        if not response.ok or response.status_code >= 400 or len(json_reply["json"]) == 0:
-            logger.warning("Cannot query JSON API: domain='%s',path='%s',data()=%d,response.status_code=%d,json_reply[]='%s'", domain, path, len(data), response.status_code, type(json_reply))
+        logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
+        if not response.ok or response.status_code >= 300 or len(response.text.strip()) == 0:
+            logger.warning("Cannot query JSON API: domain='%s',path='%s',data()=%d,response.status_code=%d,response.text()=%d", domain, path, len(data), response.status_code, len(response.text))
             json_reply["status_code"]   = response.status_code
             json_reply["error_message"] = response.reason
             instances.set_last_error(domain, response)
@@ -126,9 +126,9 @@ def fetch_api_url(url: str, timeout: tuple) -> dict:
         logger.debug("Parsing JSON response from url='%s' ...", url)
         json_reply["json"] = json_helper.from_response(response)
 
-        logger.debug("response.ok='%s',response.status_code='%s',json_reply[]='%s'", response.ok, response.status_code, type(json_reply))
-        if not response.ok or response.status_code >= 400 or len(json_reply["json"]) == 0:
-            logger.warning("Cannot query JSON API: url='%s',response.status_code=%d,json_reply[]='%s'", url, response.status_code, type(json_reply))
+        logger.debug("response.ok='%s',response.status_code='%s',response.text()=%d", response.ok, response.status_code, len(response.text), response.text)
+        if not response.ok or response.status_code >= 300 or len(response.text) == 0:
+            logger.warning("Cannot query JSON API: url='%s',response.status_code=%d,response.text()=%d", url, response.status_code, len(response.text))
             json_reply["status_code"]   = response.status_code
             json_reply["error_message"] = response.reason
             del json_reply["json"]
@@ -166,7 +166,7 @@ def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict:
             f"https://{domain}{path}",
             headers={**api_headers, **headers},
             timeout=timeout,
-            cookies=cookies.get_all(domain) if cookies.has(domain) else {},
+            cookies=cookies.get_all(domain),
             allow_redirects=False
         )
 
@@ -181,13 +181,13 @@ def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict:
     logger.debug("Parsing JSON response from domain='%s',path='%s' ...", domain, path)
     json_reply["json"] = json_helper.from_response(response)
 
-    logger.debug("response.ok='%s',response.status_code=%d,json_reply[]='%s'", response.ok, response.status_code, type(json_reply))
-    if not response.ok or response.status_code >= 400 or len(json_reply["json"]) == 0:
-        logger.warning("Cannot query JSON API: domain='%s',path='%s',response.status_code=%d,json_reply[]='%s'", domain, path, response.status_code, type(json_reply))
+    logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
+    if not response.ok or response.status_code >= 300 or len(response.text) == 0:
+        logger.warning("Cannot query JSON API: domain='%s',path='%s',response.status_code=%d,response.text()=%d", domain, path, response.status_code, len(response.text))
         json_reply["status_code"]   = response.status_code
         json_reply["error_message"] = response.reason
-        del json_reply["json"]
         instances.set_last_error(domain, response)
+        del json_reply["json"]
 
     logger.debug("Returning json_reply(%d)[]='%s' - EXIT!", len(json_reply), type(json_reply))
     return json_reply
@@ -257,7 +257,7 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: tuple) -> req
             f"https://{domain}{path}",
             headers=headers,
             timeout=timeout,
-            cookies=cookies.get_all(domain) if cookies.has(domain) else {},
+            cookies=cookies.get_all(domain),
             allow_redirects=False
         )