add followers and following

This commit is contained in:
2026-03-06 05:51:11 +00:00
parent 4b8cf3fafb
commit d342add62b

View File

@@ -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)