#!/usr/bin/python3 # -*- coding: utf-8 -*- import tweepy from config import white_kwds COLOR_RESET = "\033[0m" COLOR_REJECTED = "\033[1;31m" COLOR_ACCEPTED = "\033[1;32m" COLOR_ALREADY = "\033[1;33m" def get_displayable_content(orig, margin): """Format content to get it displayable.""" padding = '\n' + ' ' * margin useful = [ l for l in orig.split('\n') if len(l) > 0 ] result = padding.join(useful) return result def analyse(sid, username, content, api, memory): """Analyse a Tweet content.""" like = False words = content.split(' ') white = [ s.lower().replace('_', ' ') for s in white_kwds.split(' ') ] for kwd in white: for w in words: if w.lower() == kwd: like = True break if like: break if like: if memory.is_original_content(content): try: api.create_favorite(sid) memory.save_liked_status(sid, username, content) displayable = get_displayable_content(content, len('Liking') + len(' @%s: "' % username)) print(COLOR_ACCEPTED + 'Liking' + COLOR_RESET + ' @%s: "%s"' % (username, displayable)) print(' -> https://twitter.com/%s/status/%d' % (username, sid)) except tweepy.error.TweepError: pass else: displayable = get_displayable_content(content, len('Already seen "')) print(COLOR_ALREADY + 'Already seen' + COLOR_RESET + ' "%s"' % displayable) else: displayable = get_displayable_content(content, len('Reject') + len(' @%s: "' % username)) print(COLOR_REJECTED + 'Reject' + COLOR_RESET + ' @%s: "%s"' % (username, displayable))