Skip to content

Instantly share code, notes, and snippets.

@planglois925
Created September 11, 2017 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save planglois925/dd1980f5c3d547923cf7caf17c523996 to your computer and use it in GitHub Desktop.
Save planglois925/dd1980f5c3d547923cf7caf17c523996 to your computer and use it in GitHub Desktop.
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 't.co'
# 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 self.domains)
else:
pass
else:
pass
# 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