Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2017 16:14
What would you like to do?
def domain_test(self,status):
# begin by making an empty array that will store our TRUE/FALSE responses
results = []
# first lets check to see if we got URLs in our Entities object of the status
if status.entities['urls']:
# In a status we'll want to check all the urls that might be there
# so we create a very quick for loop
for domain in status.entities['urls']:
# A check to see if there's anything in our expanded url
# Twitter automatically converts MOST [if not all] urls
# into their twitter url shorting service the ''
# this is to save space on the actual tweet itself,
# however, the full expanded is still stored with the status.
# So that's where we'll grab it
if domain['expanded_url']:
# This is the meat of the script
# This part helps us determine if the expanded url is in our domain list
# It then adds a TRUE or FALSE to results
# If you want to test to see if this section is working,
# you can change this logic to just print the values, instead of storing them
# but caution, you'll be getting lots of hits depending on your track
results.append(str(urlparse(domain['expanded_url']).netloc).lower() in
# We now return if there's any TRUE's in our array
return any(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment