From d342add62b9c587593100987cd937b1894166b27 Mon Sep 17 00:00:00 2001 From: shibao Date: Fri, 6 Mar 2026 05:51:11 +0000 Subject: [PATCH] add followers and following --- misskey_export.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/misskey_export.py b/misskey_export.py index 6385ec8..e61c8ed 100644 --- a/misskey_export.py +++ b/misskey_export.py @@ -342,6 +342,54 @@ def export_antennas_db(user_id, base_path, db_conn): ) +def export_following(user_id, base_path): + print(f" Exporting following for {get_handle(user_id)}...") + with open(base_path / "following.txt", "w", encoding="utf-8") as f: + until_id = None + while True: + body = {"userId": user_id, "limit": 100} + if until_id: + body["untilId"] = until_id + res = post("/users/following", body) + res.raise_for_status() + followings = res.json() + if not followings: + break + for fol in followings: + user = fol.get("followee") + if user: + username = user.get("username") + host = user.get("host") or BASE_DOMAIN + f.write(f"@{username}@{host}\n") + if len(followings) < 100: + break + until_id = followings[-1]["id"] + + +def export_followers(user_id, base_path): + print(f" Exporting followers for {get_handle(user_id)}...") + with open(base_path / "followers.txt", "w", encoding="utf-8") as f: + until_id = None + while True: + body = {"userId": user_id, "limit": 100} + if until_id: + body["untilId"] = until_id + res = post("/users/followers", body) + res.raise_for_status() + followers = res.json() + if not followers: + break + for fol in followers: + user = fol.get("follower") + if user: + username = user.get("username") + host = user.get("host") or BASE_DOMAIN + f.write(f"@{username}@{host}\n") + if len(followers) < 100: + break + until_id = followers[-1]["id"] + + def main(): db_conn = None try: @@ -373,6 +421,8 @@ def main(): export_user_data(user, user_dir) file_id_to_path = export_drive_admin(user_id, user_dir) export_notes(user_id, user_dir, file_id_to_path) + export_following(user_id, user_dir) + export_followers(user_id, user_dir) export_lists_db(user_id, user_dir, db_conn) export_antennas_db(user_id, user_dir, db_conn)