Skip to content

Instantly share code, notes, and snippets.

@marcan
Created November 15, 2022 03:04
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcan/0edb0c50e18b37c438bee2c80730cb3f to your computer and use it in GitHub Desktop.
Save marcan/0edb0c50e18b37c438bee2c80730cb3f to your computer and use it in GitHub Desktop.
import tweepy, json, time, sys
auth = tweepy.OAuth1UserHandler(
<api keys here>
)
api = tweepy.API(auth)
d = json.loads(open(sys.argv[1]).read().split("=", 1)[1])
BATCH=100
users = []
for i in range(0, len(d), BATCH):
ids = []
for f in d[i:i+BATCH]:
ids.append(f["following"]["accountId"])
u = api.lookup_users(user_id=ids)
users.extend(i._json for i in u)
print(f"{i+100}/{len(d)}")
open("users.json", "w").write(json.dumps(users))
@jwoglom
Copy link

jwoglom commented Nov 18, 2022

FYI, the file this script is expecting as an input is data/following.js within the Twitter archive. And docs on the tweepy auth are here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment