diff options
Diffstat (limited to 'taste.py')
-rw-r--r-- | taste.py | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -7,6 +7,7 @@ import sys import tweepy from config import accepted_languages, white_kwds, cs_white_kwds, black_kwds, cs_black_kwds from config import banned_accounts, banned_accounts_re, banned_titles_re +from config import sensitive_ratio from random import randint from time import sleep @@ -70,6 +71,25 @@ def is_blacklisted(username, displayed): return result +def is_spam(content): + """Define if a given content is suitable or not.""" + + keywords = content.split(' ') + + uc_counter = 0 + + for kw in keywords: + + if kw == kw.upper(): + uc_counter += 1 + + ratio = (uc_counter * 100.0) / len(keywords) + + result = (ratio > sensitive_ratio) + + return result + + def analyse(sid, username, displayed, lang, content, api, memory): """Analyse a Tweet content.""" @@ -77,7 +97,9 @@ def analyse(sid, username, displayed, lang, content, api, memory): liked = False - if not is_blacklisted(username, displayed) and (lang in accepted_languages.split(' ')): + if not is_blacklisted(username, displayed) \ + and not is_spam(content) \ + and (lang in accepted_languages.split(' ')): like = False |