mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
First filter implementation. Needs lots of tests. #102
This commit is contained in:
parent
c2413489e5
commit
1e22ebce61
@ -74,7 +74,7 @@ class Session(object):
|
||||
if i["id"] < last_id:
|
||||
log.error("Ignoring an older tweet... Last id: {0}, tweet id: {1}".format(last_id, i["id"]))
|
||||
continue
|
||||
if utils.find_item(i["id"], self.db[name]) == None and utils.is_allowed(i, self.settings["twitter"]["ignored_clients"]) == True:
|
||||
if utils.find_item(i["id"], self.db[name]) == None and utils.is_allowed(i, self.settings, name) == True:
|
||||
try: i = self.check_quoted_status(i)
|
||||
except: pass
|
||||
i = self.check_long_tweet(i)
|
||||
|
@ -24,7 +24,7 @@ class timelinesStreamer(TwythonStreamer):
|
||||
def check_tls(self, data):
|
||||
for i in self.session.settings["other_buffers"]["timelines"]:
|
||||
if data["user"]["id_str"] == i:
|
||||
if utils.find_item(data["id"], self.session.db["%s-timeline" % (i,)]) != None:
|
||||
if utils.find_item(data["id"], self.session.db["%s-timeline" % (i,)]) != None and utils.is_allowed(data, self.session.settings, "%s-timeline" % (i,)):
|
||||
log.error("duplicated tweet. Ignoring it...")
|
||||
return
|
||||
# try:
|
||||
@ -60,7 +60,7 @@ class timelinesStreamer(TwythonStreamer):
|
||||
self.friends = friends
|
||||
|
||||
def on_success(self, data):
|
||||
if "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
||||
if "text" in data:
|
||||
if data.has_key("extended_tweet"):
|
||||
data["full_text"] = data["extended_tweet"]["full_text"]
|
||||
if data.has_key("retweeted_status"):
|
||||
|
@ -27,7 +27,7 @@ class streamer(TwythonStreamer):
|
||||
|
||||
def put_data(self, place, data):
|
||||
if self.session.db.has_key(place):
|
||||
if utils.find_item(data["id"], self.session.db[place]) != None:
|
||||
if utils.find_item(data["id"], self.session.db[place]) != None and utils.is_allowed(data, self.session.settings, place):
|
||||
log.error("duplicated tweet. Ignoring it...")
|
||||
return False
|
||||
# try:
|
||||
@ -128,7 +128,7 @@ class streamer(TwythonStreamer):
|
||||
elif "friends" in data:
|
||||
self.friends = data["friends"]
|
||||
pub.sendMessage("friends-receibed")
|
||||
elif "text" in data and utils.is_allowed(data, self.session.settings["twitter"]["ignored_clients"]) == True:
|
||||
elif "text" in data:
|
||||
if data.has_key("extended_tweet"):
|
||||
data["full_text"] = data["extended_tweet"]["full_text"]
|
||||
data["entities"] = data["extended_tweet"]["entities"]
|
||||
|
@ -128,16 +128,36 @@ def api_call(parent=None, call_name=None, preexec_message="", success="", succes
|
||||
parent.parent.sound.play("error.ogg")
|
||||
return val
|
||||
|
||||
def is_allowed(tweet, clients):
|
||||
def is_allowed(tweet, settings, buffer_name):
|
||||
clients = settings["twitter"]["ignored_clients"]
|
||||
if tweet.has_key("sender"): return True
|
||||
allowed = True
|
||||
if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"]
|
||||
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
||||
for i in clients:
|
||||
if i.lower() == source.lower():
|
||||
allowed = False
|
||||
# log.exception("Tuit not allowed: %r" % (tweet,))
|
||||
return allowed
|
||||
return False
|
||||
return filter_tweet(tweet, settings, buffer_name)
|
||||
|
||||
def filter_tweet(tweet, settings, buffer_name):
|
||||
for i in settings["filters"]:
|
||||
if settings["filters"][i]["in_buffer"] == buffer_name:
|
||||
result = True
|
||||
regexp = settings["filters"][i]["regexp"]
|
||||
word = settings["filters"][i]["word"]
|
||||
if word != "" and settings["filters"][i]["if_word_exists"]:
|
||||
if word not in tweet["full_text"]:
|
||||
return False
|
||||
elif word != "" and settings["filters"][i]["if_word_exists"] == False:
|
||||
if word in tweet["full_text"]:
|
||||
return False
|
||||
if settings["filters"][i]["in_lang"] == True:
|
||||
if tweet["lang"] not in settings["filters"][i]["languages"]:
|
||||
return False
|
||||
elif settings["filters"][i]["in_lang"] == False:
|
||||
if tweet["lang"] in settings["filters"][i]["languages"]:
|
||||
return False
|
||||
return True
|
||||
|
||||
def twitter_error(error):
|
||||
if error.error_code == 403:
|
||||
|
Loading…
Reference in New Issue
Block a user