]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 24 Jul 2023 23:58:08 +0000 (01:58 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 24 Jul 2023 23:58:08 +0000 (01:58 +0200)
- added command fetch_joinmobilizon() to fetch instances JSON for mobilizon
  (federated events)

fba/boot.py
fba/commands.py

index 0da80a09ad5c0c83f729e6b7c0fc35f7e210cde7..6d88b87b30da33d94523f344b51d8dda5c8f8224 100644 (file)
@@ -145,6 +145,13 @@ def init_parser():
     )
     parser.set_defaults(command=commands.fetch_joinfediverse)
 
+    ### Fetch instances JSON from instances.joinmobilizon.org
+    parser = subparser_command.add_parser(
+        "fetch_joinmobilizon",
+        help="Fetches instances from joinmobilizon",
+    )
+    parser.set_defaults(command=commands.fetch_joinmobilizon)
+
     ### Fetch blocks from misskey.page ###
     parser = subparser_command.add_parser(
         "fetch_joinmisskey",
index c6e14f4cb9958df7b43063d21c9fb25bd1553c75..c381f8d1befdf133091998af1c43aaf277011c9d 100644 (file)
@@ -1258,6 +1258,54 @@ def fetch_fedipact(args: argparse.Namespace) -> int:
     logger.debug("Success! - EXIT!")
     return 0
 
+def fetch_joinmobilizon(args: argparse.Namespace) -> int:
+    logger.debug("args[]='%s' - CALLED!", type(args))
+
+    logger.debug("Invoking locking.acquire() ...")
+    locking.acquire()
+
+    source_domain = "instances.joinmobilizon.org"
+    if sources.is_recent(source_domain):
+        logger.info("API from source_domain='%s' has recently being accessed - EXIT!", source_domain)
+        return 0
+    else:
+        logger.debug("source_domain='%s' has not been recently used, marking ...", source_domain)
+        #sources.update(source_domain)
+
+    logger.info("Fetching instances from source_domain='%s' ...", source_domain)
+    raw = utils.fetch_url(
+        f"https://{source_domain}/api/v1/instances",
+        network.web_headers,
+        (config.get("connection_timeout"), config.get("read_timeout"))
+    ).text
+    logger.debug("raw()=%d,raw[]='%s'", len(raw), type(raw))
+
+    parsed = json.loads(raw)
+    logger.debug("parsed[%s]()=%d", type(parsed), len(parsed))
+
+    if "data" not in parsed:
+        logger.warning("parsed()=%d does not contain key 'data'")
+        return 1
+
+    logger.info("Checking %d instances ...", len(parsed["data"]))
+    for row in parsed["data"]:
+        logger.debug("row[]='%s'", type(row))
+        if "host" not in row:
+            logger.warning("row='%s' does not contain key 'host' - SKIPPED!", row)
+            continue
+        elif not utils.is_domain_wanted(row["host"]):
+            logger.debug("row[host]='%s' is not wanted - SKIPPED!", row["host"])
+            continue
+        elif instances.is_registered(row["host"]):
+            logger.debug("row[host]='%s' is already registered - SKIPPED!", row["host"])
+            continue
+
+        logger.info("Fetching row[host]='%s' ...", row["host"])
+        federation.fetch_instances(row["host"], "demo.mobilizon.org", None, inspect.currentframe().f_code.co_name)
+
+    logger.debug("Success! - EXIT!")
+    return 0
+
 def fetch_joinmisskey(args: argparse.Namespace) -> int:
     logger.debug("args[]='%s' - CALLED!", type(args))