add followers and following
This commit is contained in:
@@ -195,7 +195,7 @@ def download_file(file_info, folder_path):
|
|||||||
# Heuristic: If it exists and matches size, assume it's already downloaded
|
# Heuristic: If it exists and matches size, assume it's already downloaded
|
||||||
if dest_path.stat().st_size == file_info.get("size"):
|
if dest_path.stat().st_size == file_info.get("size"):
|
||||||
return dest_path.name
|
return dest_path.name
|
||||||
|
|
||||||
dest_path = original_dest_path.with_name(
|
dest_path = original_dest_path.with_name(
|
||||||
f"{original_dest_path.stem}_{counter}{original_dest_path.suffix}"
|
f"{original_dest_path.stem}_{counter}{original_dest_path.suffix}"
|
||||||
)
|
)
|
||||||
@@ -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():
|
def main():
|
||||||
db_conn = None
|
db_conn = None
|
||||||
try:
|
try:
|
||||||
@@ -373,6 +421,8 @@ def main():
|
|||||||
export_user_data(user, user_dir)
|
export_user_data(user, user_dir)
|
||||||
file_id_to_path = export_drive_admin(user_id, user_dir)
|
file_id_to_path = export_drive_admin(user_id, user_dir)
|
||||||
export_notes(user_id, user_dir, file_id_to_path)
|
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_lists_db(user_id, user_dir, db_conn)
|
||||||
export_antennas_db(user_id, user_dir, db_conn)
|
export_antennas_db(user_id, user_dir, db_conn)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user