Advertisement
Guest User

basic python script for downloading Bluesky follower lists

a guest
Jul 12th, 2023
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. from atproto import Client
  2. import json
  3. import pandas as pd
  4. import time
  5.  
  6. client = Client ()
  7. client.login ("XXXXXXXXX.bsky.social", "XXXXXXXXX")
  8.  
  9. handle = "aoc.bsky.social"
  10. csv = True
  11.  
  12. def profile_to_dict_csv (profile):
  13. return {"handle" : profile["handle"],
  14. "profileImageURL" : profile["avatar"],
  15. "bio" : profile["description"],
  16. "displayName" : profile["displayName"]}
  17.  
  18. def profile_to_dict_json (profile):
  19. return profile.json ()
  20.  
  21. batch = 100
  22. parser = profile_to_dict_csv if csv else profile_to_dict_json
  23. rows = []
  24. r = client.bsky.graph.get_followers (
  25. {"actor" : handle, "limit" : batch})
  26. cursor = r["cursor"]
  27. rows.extend ([profile_to_dict_csv (p) for p in r.followers])
  28. print (str (len (rows)) + " downloaded")
  29. while cursor is not None:
  30. time.sleep (3)
  31. r = client.bsky.graph.get_followers (
  32. {"actor" : handle, "limit" : batch, "cursor" : cursor})
  33. cursor = r["cursor"]
  34. rows.extend ([profile_to_dict_csv (p) for p in r.followers])
  35. print (str (len (rows)) + " downloaded")
  36. df = pd.DataFrame (rows)
  37. print (len (df.index))
  38. print (df[["handle"]])
  39. print (len (set (df["handle"])))
  40. if csv:
  41. df.to_csv (handle + "_bsky_followers.csv", index=False)
  42. else:
  43. with open (handle + "_bsky_followers.json", "w") as f:
  44. json.dump (rows, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement