]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 22 Jul 2023 12:41:19 +0000 (14:41 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 22 Jul 2023 12:41:19 +0000 (14:41 +0200)
- added command fetch_joinmisskey to fetch instances from misskey.pages service

fba/boot.py
fba/commands.py

index 1830a6dd1fc6a35e8e7239a61445365620e21285..6d0182ab323d29c0b544d3befc81ac245466e3ee 100644 (file)
@@ -144,6 +144,13 @@ def init_parser():
     )
     parser.set_defaults(command=commands.fetch_joinfediverse)
 
+    ### Fetch blocks from misskey.page ###
+    parser = subparser_command.add_parser(
+        "fetch_joinmisskey",
+        help="Fetches instances.json from misskey.page",
+    )
+    parser.set_defaults(command=commands.fetch_joinmisskey)
+
     ### Fetch blocks from fediverse.observer ###
     parser = subparser_command.add_parser(
         "fetch_observer",
index 50700c806af25140f6b64660729b39e4b0be911b..122263b52709ffae98455c57b5278913df90f0e7 100644 (file)
@@ -1240,6 +1240,53 @@ def fetch_fedipact(args: argparse.Namespace) -> int:
     logger.debug("Success! - EXIT!")
     return 0
 
+def fetch_joinmisskey(args: argparse.Namespace) -> int:
+    logger.debug("args[]='%s' - CALLED!", type(args))
+
+    logger.debug("Invoking locking.acquire() ...")
+    locking.acquire()
+
+    source_domain = "instanceapp.misskey.page"
+    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)
+
+    raw = utils.fetch_url(
+        f"https://{source_domain}/instances.json",
+        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 "instancesInfos" not in parsed:
+        logger.warning("parsed()=%d does not contain element 'instancesInfos'")
+        return 1
+
+    logger.info("Checking %d instane(s) ...", len(parsed["instancesInfos"]))
+    for row in parsed["instancesInfos"]:
+        logger.debug("row[%s]='%s'", type(row), row)
+        if "url" not in row:
+            logger.warning("row()=%d does not have element 'url' - SKIPPED!", len(row))
+            continue
+        elif not utils.is_domain_wanted(row["url"]):
+            logger.debug("row[url]='%s' is not wanted - SKIPPED!", row["url"])
+            continue
+        elif instances.is_registered(row["url"]):
+            logger.debug("row[url]='%s' is already registered - SKIPPED!", row["url"])
+            continue
+
+        logger.info("Fetching row[url]='%s' ...", row["url"])
+        federation.fetch_instances(row["url"], "misskey.io", None, inspect.currentframe().f_code.co_name)
+
+    logger.debug("Success! - EXIT!")
+    return 0
+
 def fetch_joinfediverse(args: argparse.Namespace) -> int:
     logger.debug("args[]='%s' - CALLED!", type(args))