Ignoring clients improvements: adding clients from the action users dialog does always work, no matters the buffer the client is added

This commit is contained in:
Manuel Cortez 2014-12-10 11:19:38 -06:00
parent 2ce59cf208
commit b232a0b0ad
6 changed files with 57 additions and 35 deletions

View File

@ -186,18 +186,21 @@ class basePanel(wx.Panel):
except TwythonError as e:
output.speak(e.message)
for i in items:
if config.main["general"]["reverse_timelines"] == False:
self.db.settings[self.name_buffer].insert(0, i)
else:
self.db.settings[self.name_buffer].append(i)
if twitter.utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False:
self.db.settings[self.name_buffer].insert(0, i)
else:
self.db.settings[self.name_buffer].append(i)
if config.main["general"]["reverse_timelines"] == False:
for i in items:
tweet = self.compose_function(i, self.db)
self.list.insert_item(True, *tweet)
if twitter.utils.is_allowed(i) == True:
tweet = self.compose_function(i, self.db)
self.list.insert_item(True, *tweet)
else:
for i in items:
tweet = self.compose_function(i, self.db)
self.list.insert_item(False, *tweet)
if twitter.utils.is_allowed(i) == True:
tweet = self.compose_function(i, self.db)
self.list.insert_item(False, *tweet)
output.speak(_(u"%s items retrieved") % (len(items)))
def put_items(self, num):
@ -205,7 +208,7 @@ class basePanel(wx.Panel):
for i in self.db.settings[self.name_buffer]:
tweet = self.compose_function(i, self.db)
self.list.insert_item(False, *tweet)
self.set_list_position()
self.set_list_position()
elif self.list.get_count() > 0:
if config.main["general"]["reverse_timelines"] == False:
for i in self.db.settings[self.name_buffer][:num]:

View File

@ -23,6 +23,7 @@ import twitter
from twitter import utils
from twython import TwythonError
import output
import re
class follow(wx.Dialog):
def __init__(self, parent, default="follow"):
@ -48,6 +49,7 @@ class follow(wx.Dialog):
self.block = wx.RadioButton(panel, -1, _(u"Block"))
self.unblock = wx.RadioButton(panel, -1, _(u"Unblock"))
self.reportSpam = wx.RadioButton(panel, -1, _(u"Report as spam"))
self.ignore_client = wx.RadioButton(panel, -1, _(u"Ignore tweets from this client"))
self.setup_default(default)
actionSizer.Add(label2)
actionSizer.Add(self.follow)
@ -57,6 +59,7 @@ class follow(wx.Dialog):
actionSizer.Add(self.block)
actionSizer.Add(self.unblock)
actionSizer.Add(self.reportSpam)
actionSizer.Add(self.ignore_client)
sizer = wx.BoxSizer(wx.VERTICAL)
ok = wx.Button(panel, wx.ID_OK, _(u"OK"))
ok.Bind(wx.EVT_BUTTON, self.onok)
@ -133,6 +136,15 @@ class follow(wx.Dialog):
self.Destroy()
except TwythonError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True)
elif self.ignore_client.GetValue() == True:
tweet = self.parent.get_tweet()
if tweet.has_key("sender"):
output.speak(_(u"You can't ignore direct messages"))
return
else:
client = re.sub(r"(?s)<.*?>", "", tweet["source"])
if client not in config.main["twitter"]["ignored_clients"]:
config.main["twitter"]["ignored_clients"].append(client)
def setup_default(self, default):
if default == "follow":

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from twitter import compose
from twitter import compose, utils
from twython import TwythonStreamer
import sound
from mysc import event
@ -44,7 +44,7 @@ class streamer(TwythonStreamer):
def on_success(self, data):
try:
if data.has_key("text"):
if data.has_key("text") and utils.is_allowed(data):
self.check_tls(data)
elif "friends" in data:
self.friends = data["friends"]

View File

@ -153,7 +153,7 @@ def compose_tweet(tweet, db):
else: user = tweet["sender"]["name"]
elif tweet.has_key("user"):
user = tweet["user"]["name"]
source = re.sub(r"(?s)<.*?>", " ", tweet["source"])
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
try: text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], StripChars(tweet["retweeted_status"]["text"]))
except KeyError: text = "%s" % (StripChars(tweet["text"]))
if text[-1] in chars: text=text+"."

View File

@ -75,15 +75,16 @@ def start_stream(db, twitter, name, function, param=None):
last_id = 0
if len(db.settings[name]) > 0:
for i in tl:
if int(i["id"]) > int(last_id):
if int(i["id"]) > int(last_id) and utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
elif len(db.settings[name]) == 0:
for i in tl:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
if utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
# db.settings.update()
return num
@ -121,7 +122,7 @@ def update_stream(config, twitter, name, function, param=None, sndFile=""):
tl = function(sinze_id=config.settings[name][-1]["id"], screen_name=param, count=config.main["general"]["max_tweets_per_call"])
tl.reverse()
for i in tl:
if i["id"] > config.settings[name][-1]["id"]:
if i["id"] > config.settings[name][-1]["id"] and utils.is_allowed(i) == True:
config.settings[name].append(i)
sounded = True
num = num+1
@ -189,15 +190,16 @@ def start_list(db, twitter, name, list_id, *args, **kwargs):
last_id = 0
if len(db.settings[name]) > 0:
for i in tl:
if int(i["id"]) > int(last_id):
if int(i["id"]) > int(last_id) and utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
elif len(db.settings[name]) == 0:
for i in tl:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
if utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
db.settings.update()
return num
@ -209,15 +211,16 @@ def search(db, twitter, name, *args, **kwargs):
tl["statuses"].reverse()
if len(db.settings[name]) > 0:
for i in tl["statuses"]:
if utils.find_item(i["id"], db.settings[name]) == None:
if utils.find_item(i["id"], db.settings[name]) == None and utils.is_allowed(i):
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
elif len(db.settings[name]) == 0:
for i in tl["statuses"]:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
if utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
return num
def search_users(db, twitter, name, *args, **kwargs):
@ -247,13 +250,14 @@ def get_favourites_timeline(db, twitter, name, param, *args, **kwargs):
tl.reverse()
if len(db.settings[name]) > 0:
for i in tl:
if utils.find_item(i["id"], db.settings[name]) == None:
if utils.find_item(i["id"], db.settings[name]) == None and utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
elif len(db.settings[name]) == 0:
for i in tl:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
if utils.is_allowed(i) == True:
if config.main["general"]["reverse_timelines"] == False: db.settings[name].append(i)
else: db.settings[name].insert(0, i)
num = num+1
return num

View File

@ -109,9 +109,12 @@ def api_call(parent=None, call_name=None, preexec_message="", success="", succes
return val
def is_allowed(tweet):
allowed = True
if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"]
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
for i in config.main["twitter"]["ignored_clients"]:
if i.lower() == source.lower(): allowed = False
return allowed
try:
allowed = True
if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"]
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
for i in config.main["twitter"]["ignored_clients"]:
if i.lower() == source.lower(): allowed = False
return allowed
except KeyError:
return True