Guest User

HackMyEmail

a guest
Jun 23rd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. class BasicFilter(Filter):
  2.    
  3.     def filter(self, message_details, params):
  4.         return 'foo' if 'foo' in message_details['subject'] else ''
  5.        
  6.  
  7. class KloutFilter(Filter):
  8.    
  9.     def filter(self, message_details, params):
  10.        
  11.         # Get the Twitter username based on the from email address
  12.         username = self.getTwitterUsername(message_details['from'])
  13.        
  14.         # Couldn't find their twitter username based on their email
  15.         if not username:
  16.             return ''
  17.        
  18.         try:
  19.             # Get the Klout score of that Twitter username
  20.             score = self.getKloutScore(username)
  21.        
  22.             scoreThreshold = float(params['kloutScore'])
  23.             if params['switch'] == 'featureOff':
  24.                 return ''
  25.         except Exception as e:
  26.             logging.exception(e)
  27.             return ''
  28.        
  29.         return 'highklout' if score > scoreThreshold else ''
  30.        
  31.     def getTwitterUsername(self, email):
  32.         contact = FullContact('dc69203c420a5e5d').do_lookup(email)
  33.        
  34.         try:
  35.             profiles = contact['socialProfiles']
  36.            
  37.             username = False
  38.            
  39.             for profile in profiles:
  40.                 if profile['typeId'] == 'twitter':
  41.                     username = profile['username']
  42.                     break
  43.                
  44.             if not username:
  45.                 logging.info('Couldnt find an associated twitter for email {0}'.format(email))
  46.                 return False
  47.         except:
  48.             logging.info('Couldnt find an associated twitter for email {0}'.format(email))
  49.             return False
  50.        
  51.         return username
  52.        
  53.     def getKloutScore(self, username):
  54.         k = Klout('d8auedjhwne4zztmjyufy7ep')
  55.  
  56.         # Get kloutId of the user by inputting a twitter screenName
  57.         kloutId = k.identity.klout(screenName=username).get('id')
  58.        
  59.         # Get klout score of the user
  60.         return k.user.score(kloutId=kloutId).get('score')
Add Comment
Please, Sign In to add comment