mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Get_more_items has been implemented
This commit is contained in:
parent
1fbee07de2
commit
9ad2d6cc69
@ -66,6 +66,9 @@ class bufferController(object):
|
|||||||
def start_stream(self):
|
def start_stream(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_more_items(self):
|
||||||
|
output.speak(_(u"This action is not supported for this buffer"))
|
||||||
|
|
||||||
def put_items_on_list(self, items):
|
def put_items_on_list(self, items):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -179,6 +182,28 @@ class baseBufferController(bufferController):
|
|||||||
if number_of_items > 0 and self.name != "sent_tweets" and self.name != "sent_direct_messages":
|
if number_of_items > 0 and self.name != "sent_tweets" and self.name != "sent_direct_messages":
|
||||||
self.session.sound.play(self.sound)
|
self.session.sound.play(self.sound)
|
||||||
|
|
||||||
|
def get_more_items(self):
|
||||||
|
elements = 0
|
||||||
|
if self.session.settings["general"]["reverse_timelines"] == False:
|
||||||
|
last_id = self.session.db[self.name][0]["id"]
|
||||||
|
else:
|
||||||
|
last_id = self.session.db[self.name_buffer][-1]["id"]
|
||||||
|
try:
|
||||||
|
items = self.session.get_more_items(self.function, count=self.session.settings["general"]["max_tweets_per_call"], max_id=last_id, *self.args, **self.kwargs)
|
||||||
|
except TwythonError as e:
|
||||||
|
output.speak(e.message)
|
||||||
|
for i in items:
|
||||||
|
if utils.is_allowed(i, self.session.settings["twitter"]["ignored_clients"]) == True:
|
||||||
|
elements +=1
|
||||||
|
if self.session.settings["general"]["reverse_timelines"] == False:
|
||||||
|
self.session.db[self.name].insert(0, i)
|
||||||
|
else:
|
||||||
|
self.session.db[self.name].append(i)
|
||||||
|
selection = self.buffer.list.get_selected()
|
||||||
|
self.put_items_on_list(elements)
|
||||||
|
self.buffer.list.select_item(selection+elements)
|
||||||
|
output.speak(_(u"%s items retrieved") % (str(elements)))
|
||||||
|
|
||||||
def put_items_on_list(self, number_of_items):
|
def put_items_on_list(self, number_of_items):
|
||||||
log.debug("The list contains %d items " % (self.buffer.list.get_count(),))
|
log.debug("The list contains %d items " % (self.buffer.list.get_count(),))
|
||||||
log.debug("Putting %d items on the list" % (number_of_items,))
|
log.debug("Putting %d items on the list" % (number_of_items,))
|
||||||
@ -378,6 +403,22 @@ class peopleBufferController(baseBufferController):
|
|||||||
# log.debug("Number of items retrieved: %d" % (val,))
|
# log.debug("Number of items retrieved: %d" % (val,))
|
||||||
self.put_items_on_list(val)
|
self.put_items_on_list(val)
|
||||||
|
|
||||||
|
def get_more_items(self):
|
||||||
|
try:
|
||||||
|
items = self.session.get_more_items(self.function, users=True, name=self.name, count=self.session.settings["general"]["max_tweets_per_call"], cursor=self.session.db[self.name]["cursor"])
|
||||||
|
except TwythonError as e:
|
||||||
|
output.speak(e.message)
|
||||||
|
return
|
||||||
|
for i in items:
|
||||||
|
if self.session.settings["general"]["reverse_timelines"] == False:
|
||||||
|
self.session.db[self.name]["items"].insert(0, i)
|
||||||
|
else:
|
||||||
|
self.session.db[self.name]["items"].append(i)
|
||||||
|
selected = self.buffer.list.get_selected()
|
||||||
|
self.put_items_on_list(len(items))
|
||||||
|
self.buffer.list.select_item(selected+len(items))
|
||||||
|
output.speak(_(u"%s items retrieved") % (len(items)))
|
||||||
|
|
||||||
def put_items_on_list(self, number_of_items):
|
def put_items_on_list(self, number_of_items):
|
||||||
log.debug("The list contains %d items" % (self.buffer.list.get_count(),))
|
log.debug("The list contains %d items" % (self.buffer.list.get_count(),))
|
||||||
# log.debug("Putting %d items on the list..." % (number_of_items,))
|
# log.debug("Putting %d items on the list..." % (number_of_items,))
|
||||||
@ -391,7 +432,7 @@ class peopleBufferController(baseBufferController):
|
|||||||
if self.session.settings["general"]["reverse_timelines"] == False:
|
if self.session.settings["general"]["reverse_timelines"] == False:
|
||||||
for i in self.session.db[self.name]["items"][:number_of_items]:
|
for i in self.session.db[self.name]["items"][:number_of_items]:
|
||||||
tweet = self.compose_function(i, self.session.db)
|
tweet = self.compose_function(i, self.session.db)
|
||||||
self.buffers.list.insert_item(False, *tweet)
|
self.buffer.list.insert_item(False, *tweet)
|
||||||
else:
|
else:
|
||||||
for i in self.session.db[self.name]["items"][0:number_of_items]:
|
for i in self.session.db[self.name]["items"][0:number_of_items]:
|
||||||
tweet = self.compose_function(i, self.session.db)
|
tweet = self.compose_function(i, self.session.db)
|
||||||
|
@ -121,7 +121,7 @@ class Controller(object):
|
|||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.report, menuitem=self.view.report)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.report, menuitem=self.view.report)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.block, menuitem=self.view.block)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.block, menuitem=self.view.block)
|
||||||
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.unblock, menuitem=self.view.unblock)
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.unblock, menuitem=self.view.unblock)
|
||||||
|
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.get_more_items, menuitem=self.view.load_previous_items)
|
||||||
widgetUtils.connect_event(self.view.nb, widgetUtils.NOTEBOOK_PAGE_CHANGED, self.buffer_changed)
|
widgetUtils.connect_event(self.view.nb, widgetUtils.NOTEBOOK_PAGE_CHANGED, self.buffer_changed)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -541,6 +541,9 @@ class Controller(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_more_items(self, *args, **kwargs):
|
||||||
|
self.get_current_buffer().get_more_items()
|
||||||
|
|
||||||
def skip_buffer(self, forward=True):
|
def skip_buffer(self, forward=True):
|
||||||
buff = self.get_current_buffer()
|
buff = self.get_current_buffer()
|
||||||
if buff.invisible == False:
|
if buff.invisible == False:
|
||||||
|
@ -135,6 +135,16 @@ class Session(object):
|
|||||||
else:
|
else:
|
||||||
self.twitter.authorise(self.settings)
|
self.twitter.authorise(self.settings)
|
||||||
|
|
||||||
|
def get_more_items(self, update_function, users=False, name=None, *args, **kwargs):
|
||||||
|
results = []
|
||||||
|
data = getattr(self.twitter.twitter, update_function)(*args, **kwargs)
|
||||||
|
if users == True:
|
||||||
|
self.db[name]["cursor"] = data["next_cursor"]
|
||||||
|
for i in data["users"]: results.append(i)
|
||||||
|
else:
|
||||||
|
results.extend(data[1:])
|
||||||
|
return results
|
||||||
|
|
||||||
def api_call(self, call_name, action="", _sound=None, report_success=False, report_failure=True, preexec_message="", *args, **kwargs):
|
def api_call(self, call_name, action="", _sound=None, report_success=False, report_failure=True, preexec_message="", *args, **kwargs):
|
||||||
|
|
||||||
""" Make a call to the Twitter API. If there is a connectionError or another exception not related to Twitter, It will call to the method at least 25 times, waiting a while between calls. Useful for post methods.
|
""" Make a call to the Twitter API. If there is a connectionError or another exception not related to Twitter, It will call to the method at least 25 times, waiting a while between calls. Useful for post methods.
|
||||||
@ -159,9 +169,9 @@ class Session(object):
|
|||||||
if report_failure and hasattr(e, 'message'):
|
if report_failure and hasattr(e, 'message'):
|
||||||
output.speak(_("%s failed. Reason: %s") % (action, e.message))
|
output.speak(_("%s failed. Reason: %s") % (action, e.message))
|
||||||
finished = True
|
finished = True
|
||||||
# except:
|
except:
|
||||||
# tries = tries + 1
|
tries = tries + 1
|
||||||
# time.sleep(5)
|
time.sleep(5)
|
||||||
if report_success:
|
if report_success:
|
||||||
output.speak(_("%s succeeded.") % action)
|
output.speak(_("%s succeeded.") % action)
|
||||||
if _sound != None: self.sound.play(_sound)
|
if _sound != None: self.sound.play(_sound)
|
||||||
@ -255,16 +265,16 @@ class Session(object):
|
|||||||
|
|
||||||
items_ = []
|
items_ = []
|
||||||
try:
|
try:
|
||||||
if self.db[name].has_key("next_cursor"):
|
if self.db[name].has_key("cursor"):
|
||||||
next_cursor = self.db[name]["next_cursor"]
|
cursor = self.db[name]["cursor"]
|
||||||
else:
|
else:
|
||||||
next_cursor = -1
|
cursor = -1
|
||||||
except KeyError:
|
except KeyError:
|
||||||
next_cursor = -1
|
cursor = -1
|
||||||
tl = getattr(self.twitter.twitter, function)(cursor=next_cursor, count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs)
|
tl = getattr(self.twitter.twitter, function)(cursor=cursor, count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs)
|
||||||
tl[items].reverse()
|
tl[items].reverse()
|
||||||
num = self.order_cursored_buffer(name, tl[items])
|
num = self.order_cursored_buffer(name, tl[items])
|
||||||
self.db[name]["next_cursor"] = tl["next_cursor"]
|
self.db[name]["cursor"] = tl["next_cursor"]
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def start_streaming(self):
|
def start_streaming(self):
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import url_shortener, re
|
import url_shortener, re
|
||||||
""" Some utilities for the twitter interface."""
|
|
||||||
import output
|
import output
|
||||||
from twython import TwythonError
|
from twython import TwythonError
|
||||||
import config
|
import config
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger("twitter.utils")
|
||||||
|
""" Some utilities for the twitter interface."""
|
||||||
|
|
||||||
__version__ = 0.1
|
__version__ = 0.1
|
||||||
__doc__ = "Find urls in tweets and #audio hashtag."
|
__doc__ = "Find urls in tweets and #audio hashtag."
|
||||||
@ -96,11 +98,11 @@ def api_call(parent=None, call_name=None, preexec_message="", success="", succes
|
|||||||
parent.parent.sound.play("error.wav")
|
parent.parent.sound.play("error.wav")
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def is_allowed(tweet):
|
def is_allowed(tweet, clients):
|
||||||
allowed = True
|
allowed = True
|
||||||
if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"]
|
if tweet.has_key("retweeted_status"): tweet = tweet["retweeted_status"]
|
||||||
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
source = re.sub(r"(?s)<.*?>", "", tweet["source"])
|
||||||
for i in config.main["twitter"]["ignored_clients"]:
|
for i in clients:
|
||||||
if i.lower() == source.lower():
|
if i.lower() == source.lower():
|
||||||
allowed = False
|
allowed = False
|
||||||
log.exception("Tuit not allowed: %s" % (tweet["text"],))
|
log.exception("Tuit not allowed: %s" % (tweet["text"],))
|
||||||
|
@ -60,6 +60,7 @@ class mainFrame(wx.Frame):
|
|||||||
|
|
||||||
# buffer menu
|
# buffer menu
|
||||||
buffer = wx.Menu()
|
buffer = wx.Menu()
|
||||||
|
self.load_previous_items = buffer.Append(wx.NewId(), _(u"&Load previous items"))
|
||||||
self.mute = buffer.Append(wx.NewId(), _(u"&Mute"))
|
self.mute = buffer.Append(wx.NewId(), _(u"&Mute"))
|
||||||
self.mute.Enable(False)
|
self.mute.Enable(False)
|
||||||
self.autoread = buffer.Append(wx.NewId(), _(u"&Autoread tweets for this buffer"))
|
self.autoread = buffer.Append(wx.NewId(), _(u"&Autoread tweets for this buffer"))
|
||||||
|
Loading…
Reference in New Issue
Block a user