Filter by retweet, quotes and replies in filter creation #102

This commit is contained in:
Manuel Cortez 2018-02-27 16:43:16 -06:00
parent 652d3c7ff8
commit 612f4ffadf
3 changed files with 28 additions and 4 deletions

View File

@ -14,6 +14,9 @@ class filter(object):
contains = self.dialog.get("contains")
term = self.dialog.get("term")
regexp = self.dialog.get("regexp")
allow_rts = self.dialog.get("allow_rts")
allow_quotes = self.dialog.get("allow_quotes")
allow_replies = self.dialog.get("allow_replies")
load_language = self.dialog.get("load_language")
ignore_language = self.dialog.get("ignore_language")
lang_option = None
@ -26,7 +29,7 @@ class filter(object):
for i in application.supported_languages:
if i["name"] in langs:
langcodes.append(i["code"])
d = dict(in_buffer=self.buffer.name, word=term, regexp=regexp, in_lang=lang_option, languages=langcodes, if_word_exists=contains)
d = dict(in_buffer=self.buffer.name, word=term, regexp=regexp, in_lang=lang_option, languages=langcodes, if_word_exists=contains, allow_rts=allow_rts, allow_quotes=allow_quotes, allow_replies=allow_replies)
if self.buffer.session.settings["filters"].has_key(title):
return commonMessageDialogs.existing_filter()
self.buffer.session.settings["filters"][title] = d
@ -49,7 +52,6 @@ class filterManager(object):
def insert_filters(self, filters):
self.dialog.filters.clear()
for f in filters.keys():
# ToDo: Add titles to filters.
filterName = f
buffer = filters[f]["in_buffer"]
if filters[f]["if_word_exists"] == "True" and filters[f]["word"] != "":

View File

@ -148,14 +148,21 @@ def is_allowed(tweet, settings, buffer_name):
clients = settings["twitter"]["ignored_clients"]
if tweet.has_key("sender"): return True
allowed = True
tweet_data = {}
if tweet.has_key("retweeted_status"):
tweet_data["retweet"] = True
if tweet["in_reply_to_status_id_str"] != None:
tweet_data["reply"] = True
if tweet.has_key("quoted_status"):
tweet_data["quote"] = 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():
return False
return filter_tweet(tweet, settings, buffer_name)
return filter_tweet(tweet, tweet_data, settings, buffer_name)
def filter_tweet(tweet, settings, buffer_name):
def filter_tweet(tweet, tweet_data, settings, buffer_name):
if tweet.has_key("full_text"):
value = "full_text"
else:
@ -164,6 +171,15 @@ def filter_tweet(tweet, settings, buffer_name):
if settings["filters"][i]["in_buffer"] == buffer_name:
regexp = settings["filters"][i]["regexp"]
word = settings["filters"][i]["word"]
allow_rts = settings["filters"][i]["allow_rts"]
allow_quotes = settings["filters"][i]["allow_quotes"]
allow_replies = settings["filters"][i]["allow_replies"]
if allow_rts == "False" and tweet_data.has_key("retweet"):
return False
if allow_quotes == "False" and tweet_data.has_key("quote"):
return False
if allow_replies == "False" and tweet_data.has_key("reply"):
return False
if word != "" and settings["filters"][i]["if_word_exists"]:
if word in tweet[value]:
return False

View File

@ -32,6 +32,12 @@ class filterDialog(baseDialog.BaseWXDialog):
dc = wx.WindowDC(self.term)
dc.SetFont(self.term.GetFont())
self.term.SetSize(dc.GetTextExtent("0"*40))
self.allow_rts = wx.CheckBox(panel, wx.NewId(), _(u"Allow retweets"))
self.allow_quotes = wx.CheckBox(panel, wx.NewId(), _(u"Allow quoted tweets"))
self.allow_replies = wx.CheckBox(panel, wx.NewId(), _(u"Allow replies"))
self.allow_rts.SetValue(True)
self.allow_quotes.SetValue(True)
self.allow_replies.SetValue(True)
bsizer = wx.BoxSizer(wx.HORIZONTAL)
bsizer.Add(label, 0, wx.ALL, 5)
bsizer.Add(self.term, 0, wx.ALL, 5)