Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BasicFilter(Filter):
- def filter(self, message_details, params):
- return 'foo' if 'foo' in message_details['subject'] else ''
- class KloutFilter(Filter):
- def filter(self, message_details, params):
- # Get the Twitter username based on the from email address
- username = self.getTwitterUsername(message_details['from'])
- # Couldn't find their twitter username based on their email
- if not username:
- return ''
- try:
- # Get the Klout score of that Twitter username
- score = self.getKloutScore(username)
- scoreThreshold = float(params['kloutScore'])
- if params['switch'] == 'featureOff':
- return ''
- except Exception as e:
- logging.exception(e)
- return ''
- return 'highklout' if score > scoreThreshold else ''
- def getTwitterUsername(self, email):
- contact = FullContact('dc69203c420a5e5d').do_lookup(email)
- try:
- profiles = contact['socialProfiles']
- username = False
- for profile in profiles:
- if profile['typeId'] == 'twitter':
- username = profile['username']
- break
- if not username:
- logging.info('Couldnt find an associated twitter for email {0}'.format(email))
- return False
- except:
- logging.info('Couldnt find an associated twitter for email {0}'.format(email))
- return False
- return username
- def getKloutScore(self, username):
- k = Klout('d8auedjhwne4zztmjyufy7ep')
- # Get kloutId of the user by inputting a twitter screenName
- kloutId = k.identity.klout(screenName=username).get('id')
- # Get klout score of the user
- return k.user.score(kloutId=kloutId).get('score')
Add Comment
Please, Sign In to add comment