Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from atproto import Client
- import json
- import pandas as pd
- import time
- client = Client ()
- client.login ("XXXXXXXXX.bsky.social", "XXXXXXXXX")
- handle = "aoc.bsky.social"
- csv = True
- def profile_to_dict_csv (profile):
- return {"handle" : profile["handle"],
- "profileImageURL" : profile["avatar"],
- "bio" : profile["description"],
- "displayName" : profile["displayName"]}
- def profile_to_dict_json (profile):
- return profile.json ()
- batch = 100
- parser = profile_to_dict_csv if csv else profile_to_dict_json
- rows = []
- r = client.bsky.graph.get_followers (
- {"actor" : handle, "limit" : batch})
- cursor = r["cursor"]
- rows.extend ([profile_to_dict_csv (p) for p in r.followers])
- print (str (len (rows)) + " downloaded")
- while cursor is not None:
- time.sleep (3)
- r = client.bsky.graph.get_followers (
- {"actor" : handle, "limit" : batch, "cursor" : cursor})
- cursor = r["cursor"]
- rows.extend ([profile_to_dict_csv (p) for p in r.followers])
- print (str (len (rows)) + " downloaded")
- df = pd.DataFrame (rows)
- print (len (df.index))
- print (df[["handle"]])
- print (len (set (df["handle"])))
- if csv:
- df.to_csv (handle + "_bsky_followers.csv", index=False)
- else:
- with open (handle + "_bsky_followers.json", "w") as f:
- json.dump (rows, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement