Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2017 16:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
def user_mention(self, status):
# Once again we create an empty array
results = []
# Here we want to check the user mentions component of the status
# So the first step is to identify if it's empty or not
if status.entities['user_mentions']:
# Multiple users can be mentioned in a tweet,
# so we'll want to build a for-loop
for user in status.entities['user_mentions']:
# We lower our results like we lowered our input to compare them
# For our case, we're pulling out the value of screen_name, this is
# based on the assumption that you're tracking the screen names of the user's.
# Alternatively you could use their id, but you'd need to set up a process to get
# the ids first.
results.append(str(user['screen_name']).lower() in self.twitter_accounts)
# We want to return if there's any that true in our array
return any(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment