Last active
May 27, 2020 15:37
-
-
Save edsu/f3340dca45c3e8cbacdccca3137d5d56 to your computer and use it in GitHub Desktop.
Collect tweet JSON for tweets that mention particular users.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Listen for tweets mentioning particular users. | |
""" | |
import json | |
import twarc | |
twitter = twarc.Twarc() | |
users = ['jack', 'yoyoel'] | |
for tweet in twitter.filter(','.join(users)): | |
# if it's > 140 chars look for the users in the extended_tweet | |
if 'extended_tweet' in tweet: | |
user_mentions = tweet['extended_tweet']['entities']['user_mentions'] | |
else: | |
user_mentions = tweet['entities']['user_mentions'] | |
found = False | |
for mention in user_mentions: | |
if mention['screen_name'].lower() in users: | |
found = True | |
if found: | |
print(json.dumps(tweet)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment