Merge pull request #347 from manuelcortez/tweepy

Migration to Tweepy. Closes #237 , closes #240
This commit is contained in:
Manuel Cortez 2021-01-20 17:50:19 -06:00 committed by GitHub
commit b3c24c6734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 615 additions and 639 deletions

View File

@ -3,11 +3,13 @@
## changes in this version ## changes in this version
* Fixed error when displaying an URL at the end of a line, when the tweet or direct message contained multiple lines. Now the URL should be displayed correctly. ([#305,](https://github.com/manuelcortez/TWBlue/issues/305)) * Fixed error when displaying an URL at the end of a line, when the tweet or direct message contained multiple lines. Now the URL should be displayed correctly. ([#305,](https://github.com/manuelcortez/TWBlue/issues/305))
* TWBlue has been migrated completely to Python 3 (currently, the software builds with Python 3.7). * TWBlue has been migrated completely to Python 3 (currently, the software builds with Python 3.8).
* TWBlue should be restarted gracefully. Before, the application was alerting users of not being closed properly every time the application restarted by itself. * TWBlue should be restarted gracefully. Before, the application was alerting users of not being closed properly every time the application restarted by itself.
* If TWBlue attemps to load an account with invalid tokens (this happens when reactivating a previously deactivated account, or when access to the ap is revoqued), TWBlue will inform the user about this error and will skip the account. Before, the app was unable to start due to a critical error. ([#328,](https://github.com/manuelcortez/TWBlue/issues/328)) * If TWBlue attemps to load an account with invalid tokens (this happens when reactivating a previously deactivated account, or when access to the ap is revoqued), TWBlue will inform the user about this error and will skip the account. Before, the app was unable to start due to a critical error. ([#328,](https://github.com/manuelcortez/TWBlue/issues/328))
* When sending a direct message, the title of the window will change appropiately when the recipient is edited. ([#276,](https://github.com/manuelcortez/TWBlue/issues/276)) * When sending a direct message, the title of the window will change appropiately when the recipient is edited. ([#276,](https://github.com/manuelcortez/TWBlue/issues/276))
* URL'S in user profiles are expanded automatically. ([#275,](https://github.com/manuelcortez/TWBlue/issues/275)) * URL'S in user profiles are expanded automatically. ([#275,](https://github.com/manuelcortez/TWBlue/issues/275))
* TWBlue now uses [Tweepy,](https://github.com/tweepy/tweepy) to connect with Twitter. We have adopted this change in order to support Twitter'S API V 2 in the very near future. ([#333,](https://github.com/manuelcortez/TWBlue/issues/337) [#347](https://github.com/manuelcortez/TWBlue/pull/347))
* TWBlue can upload images in Tweets and replies again. ([#240,](https://github.com/manuelcortez/TWBlue/issues/240))
## Changes in version 0.95 ## Changes in version 0.95

View File

@ -25,7 +25,7 @@ pypiwin32
certifi certifi
backports.functools_lru_cache backports.functools_lru_cache
cx_freeze cx_freeze
git+https://github.com/manuelcortez/twython tweepy
git+https://github.com/manuelcortez/libloader git+https://github.com/manuelcortez/libloader
git+https://github.com/manuelcortez/platform_utils git+https://github.com/manuelcortez/platform_utils
git+https://github.com/manuelcortez/accessible_output2 git+https://github.com/manuelcortez/accessible_output2

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from builtins import str
from builtins import range
import time import time
import platform import platform
if platform.system() == "Windows": if platform.system() == "Windows":
@ -24,7 +21,8 @@ from audio_services import youtube_utils
from controller.buffers import baseBuffers from controller.buffers import baseBuffers
from sessions.twitter import compose, utils from sessions.twitter import compose, utils
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
from twython import TwythonError from tweepy.error import TweepError
from tweepy.cursor import Cursor
from pubsub import pub from pubsub import pub
from sessions.twitter.long_tweets import twishort, tweets from sessions.twitter.long_tweets import twishort, tweets
@ -86,6 +84,7 @@ class baseBufferController(baseBuffers.buffer):
return _(u"Unknown buffer") return _(u"Unknown buffer")
def post_status(self, *args, **kwargs): def post_status(self, *args, **kwargs):
item = None
title = _(u"Tweet") title = _(u"Tweet")
caption = _(u"Write the tweet here") caption = _(u"Write the tweet here")
tweet = messages.tweet(self.session, title, caption, "") tweet = messages.tweet(self.session, title, caption, "")
@ -101,8 +100,8 @@ class baseBufferController(baseBuffers.buffer):
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1) text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1)
if not hasattr(tweet, "attachments") or len(tweet.attachments) == 0: if not hasattr(tweet, "attachments") or len(tweet.attachments) == 0:
item = self.session.api_call(call_name="update_status", status=text, _sound="tweet_send.ogg", tweet_mode="extended") item = self.session.api_call(call_name="update_status", status=text, _sound="tweet_send.ogg", tweet_mode="extended")
# else: else:
# call_threaded(self.post_with_media, text=text, attachments=tweet.attachments, _sound="tweet_send.ogg") call_threaded(self.post_with_media, text=text, attachments=tweet.attachments)
if item != None: if item != None:
pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"]) pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"])
if hasattr(tweet.message, "destroy"): tweet.message.destroy() if hasattr(tweet.message, "destroy"): tweet.message.destroy()
@ -111,11 +110,12 @@ class baseBufferController(baseBuffers.buffer):
def post_with_media(self, text, attachments): def post_with_media(self, text, attachments):
media_ids = [] media_ids = []
for i in attachments: for i in attachments:
photo = open(i["file"], "rb") img = self.session.twitter.media_upload(i["file"])
img = self.session.twitter.upload_media(media=photo) self.session.twitter.create_media_metadata(media_id=img.media_id, alt_text=i["description"])
self.session.twitter.create_metadata(media_id=img["media_id"], alt_text=dict(text=i["description"])) media_ids.append(img.media_id)
media_ids.append(img["media_id"]) item = self.session.twitter.update_status(status=text, media_ids=media_ids)
self.session.twitter.update_status(status=text, media_ids=media_ids) if item != None:
pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"])
def get_formatted_message(self): def get_formatted_message(self):
if self.type == "dm" or self.name == "direct_messages": if self.type == "dm" or self.name == "direct_messages":
@ -129,25 +129,25 @@ class baseBufferController(baseBuffers.buffer):
def get_full_tweet(self): def get_full_tweet(self):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
tweetsList = [] tweetsList = []
tweet_id = tweet["id"] tweet_id = tweet.id
message = None message = None
if "message" in tweet: if hasattr(tweet, "message"):
message = tweet["message"] message = tweet.message
try: try:
tweet = self.session.twitter.show_status(id=tweet_id, include_ext_alt_text=True, tweet_mode="extended") tweet = self.session.twitter.get_status(id=tweet_id, include_ext_alt_text=True, tweet_mode="extended")
tweet["full_text"] = utils.expand_urls(tweet["full_text"], tweet["entities"]) tweet.full_text = utils.expand_urls(tweet.full_text, tweet.entities)
except TwythonError as e: except TweepError as e:
utils.twitter_error(e) utils.twitter_error(e)
return return
if message != None: if message != None:
tweet["message"] = message tweet.message = message
l = tweets.is_long(tweet) l = tweets.is_long(tweet)
while l != False: while l != False:
tweetsList.append(tweet) tweetsList.append(tweet)
try: try:
tweet = self.session.twitter.show_status(id=l, include_ext_alt_text=True, tweet_mode="extended") tweet = self.session.twitter.get_status(id=l, include_ext_alt_text=True)
tweet["full_text"] = utils.expand_urls(tweet["full_text"], tweet["entities"]) tweet.full_text = utils.expand_urls(tweet.full_text, tweet.entities)
except TwythonError as e: except TweepError as e:
utils.twitter_error(e) utils.twitter_error(e)
return return
l = tweets.is_long(tweet) l = tweets.is_long(tweet)
@ -162,18 +162,35 @@ class baseBufferController(baseBuffers.buffer):
self.execution_time = current_time self.execution_time = current_time
log.debug("Starting stream for buffer %s, account %s and type %s" % (self.name, self.account, self.type)) log.debug("Starting stream for buffer %s, account %s and type %s" % (self.name, self.account, self.type))
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs)) log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))
if self.name == "direct_messages": if self.name != "direct_messages":
number_of_items = self.session.get_cursored_stream(self.name, self.function, *self.args, **self.kwargs)
else:
val = self.session.call_paged(self.function, *self.args, **self.kwargs) val = self.session.call_paged(self.function, *self.args, **self.kwargs)
else:
# 50 results are allowed per API call, so let's assume max value can be 50.
# reference: https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/list-events
if self.session.settings["general"]["max_tweets_per_call"] > 50:
count = 50
else:
count = self.session.settings["general"]["max_tweets_per_call"]
# try to retrieve the cursor for the current buffer.
cursor = self.session.db["cursors"].get(self.name)
try:
# We need to assign all results somewhere else so the cursor variable would b generated.
val = Cursor(getattr(self.session.twitter, self.function), *self.args, **self.kwargs).items(count)
results = [i for i in val]
self.session.db["cursors"][self.name] = val.page_iterator.next_cursor
val = results
val.reverse()
except TweepError as e:
log.error("Error %s: %s" % (e.api_code, e.reason))
return
number_of_items = self.session.order_buffer(self.name, val) number_of_items = self.session.order_buffer(self.name, val)
log.debug("Number of items retrieved: %d" % (number_of_items,)) log.debug("Number of items retrieved: %d" % (number_of_items,))
self.put_items_on_list(number_of_items) self.put_items_on_list(number_of_items)
if hasattr(self, "finished_timeline") and self.finished_timeline == False: if hasattr(self, "finished_timeline") and self.finished_timeline == False:
if "-timeline" in self.name: if "-timeline" in self.name:
self.username = val[0]["user"]["screen_name"] self.username = val[0].user.screen_name
elif "-favorite" in self.name: elif "-favorite" in self.name:
self.username = self.session.api_call("show_user", **self.kwargs)["screen_name"] self.username = self.session.api_call("get_user", **self.kwargs).screen_name
self.finished_timeline = True self.finished_timeline = True
if number_of_items > 0 and self.name != "sent_tweets" and self.name != "sent_direct_messages" and self.sound != None and self.session.settings["sound"]["session_mute"] == False and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and play_sound == True: if number_of_items > 0 and self.name != "sent_tweets" and self.name != "sent_direct_messages" and self.sound != None and self.session.settings["sound"]["session_mute"] == False and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and play_sound == True:
self.session.sound.play(self.sound) self.session.sound.play(self.sound)
@ -196,17 +213,18 @@ class baseBufferController(baseBuffers.buffer):
def get_more_items(self): def get_more_items(self):
elements = [] elements = []
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
last_id = self.session.db[self.name][0]["id"] last_id = self.session.db[self.name][0].id
else: else:
last_id = self.session.db[self.name][-1]["id"] last_id = self.session.db[self.name][-1].id
try: 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) items = Cursor(getattr(self.session.twitter, self.function), max_id=last_id, *self.args, **self.kwargs).items(self.session.settings["general"]["max_tweets_per_call"])
except TwythonError as e: except TweepError as e:
output.speak(e.message, True) log.error("Error %s: %s" % (e.api_code, e.reason))
return
if items == None: if items == None:
return return
for i in items: for i in items:
if utils.is_allowed(i, self.session.settings, self.name) == True and utils.find_item(i["id"], self.session.db[self.name]) == None: if utils.is_allowed(i, self.session.settings, self.name) == True and utils.find_item(i.id, self.session.db[self.name]) == None:
i = self.session.check_quoted_status(i) i = self.session.check_quoted_status(i)
i = self.session.check_long_tweet(i) i = self.session.check_long_tweet(i)
elements.append(i) elements.append(i)
@ -223,8 +241,6 @@ class baseBufferController(baseBuffers.buffer):
for i in items: for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(False, *tweet) self.buffer.list.insert_item(False, *tweet)
# self.buffer.list.select_item(selection+elements)
# else:
self.buffer.list.select_item(selection) self.buffer.list.select_item(selection)
output.speak(_(u"%s items retrieved") % (str(len(elements))), True) output.speak(_(u"%s items retrieved") % (str(len(elements))), True)
@ -264,16 +280,12 @@ class baseBufferController(baseBuffers.buffer):
def remove_tweet(self, id): def remove_tweet(self, id):
if type(self.session.db[self.name]) == dict: return if type(self.session.db[self.name]) == dict: return
for i in range(0, len(self.session.db[self.name])): for i in range(0, len(self.session.db[self.name])):
if self.session.db[self.name][i]["id"] == id: if self.session.db[self.name][i].id == id:
self.session.db[self.name].pop(i) self.session.db[self.name].pop(i)
self.remove_item(i) self.remove_item(i)
def put_items_on_list(self, number_of_items): def put_items_on_list(self, number_of_items):
# Define the list we're going to use as cursored stuff are a bit different.
if self.name != "direct_messages" and self.name != "sent_direct_messages":
list_to_use = self.session.db[self.name] list_to_use = self.session.db[self.name]
else:
list_to_use = self.session.db[self.name]["items"]
if number_of_items == 0 and self.session.settings["general"]["persist_size"] == 0: return if number_of_items == 0 and self.session.settings["general"]["persist_size"] == 0: return
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,))
@ -376,8 +388,8 @@ class baseBufferController(baseBuffers.buffer):
self.show_menu(widgetUtils.MENU, pos=self.buffer.list.list.GetPosition()) self.show_menu(widgetUtils.MENU, pos=self.buffer.list.list.GetPosition())
def get_tweet(self): def get_tweet(self):
if "retweeted_status" in self.session.db[self.name][self.buffer.list.get_selected()]: if hasattr(self.session.db[self.name][self.buffer.list.get_selected()], "retweeted_status"):
tweet = self.session.db[self.name][self.buffer.list.get_selected()]["retweeted_status"] tweet = self.session.db[self.name][self.buffer.list.get_selected()].retweeted_status
else: else:
tweet = self.session.db[self.name][self.buffer.list.get_selected()] tweet = self.session.db[self.name][self.buffer.list.get_selected()]
return tweet return tweet
@ -389,9 +401,9 @@ class baseBufferController(baseBuffers.buffer):
@_tweets_exist @_tweets_exist
def reply(self, *args, **kwargs): def reply(self, *args, **kwargs):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
screen_name = tweet["user"]["screen_name"] screen_name = tweet.user.screen_name
id = tweet["id"] id = tweet.id
twishort_enabled = "twishort" in tweet twishort_enabled = hasattr(tweet, "twishort")
users = utils.get_all_mentioned(tweet, self.session.db, field="screen_name") users = utils.get_all_mentioned(tweet, self.session.db, field="screen_name")
ids = utils.get_all_mentioned(tweet, self.session.db, field="id_str") ids = utils.get_all_mentioned(tweet, self.session.db, field="id_str")
# Build the window title # Build the window title
@ -426,7 +438,6 @@ class baseBufferController(baseBuffers.buffer):
else: else:
params["call_name"] = "update_status_with_media" params["call_name"] = "update_status_with_media"
params["media"] = message.file params["media"] = message.file
item = self.session.api_call(**params) item = self.session.api_call(**params)
if item != None: if item != None:
pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"]) pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"])
@ -437,44 +448,33 @@ class baseBufferController(baseBuffers.buffer):
def send_message(self, *args, **kwargs): def send_message(self, *args, **kwargs):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
if self.type == "dm": if self.type == "dm":
screen_name = self.session.get_user(tweet["message_create"]["sender_id"])["screen_name"] screen_name = self.session.get_user(tweet.message_create["sender_id"]).screen_name
users = [screen_name] users = [screen_name]
elif self.type == "people": elif self.type == "people":
screen_name = tweet["screen_name"] screen_name = tweet.screen_name
users = [screen_name] users = [screen_name]
else: else:
screen_name = tweet["user"]["screen_name"] screen_name = tweet.user.screen_name
users = utils.get_all_users(tweet, self.session.db) users = utils.get_all_users(tweet, self.session.db)
dm = messages.dm(self.session, _(u"Direct message to %s") % (screen_name,), _(u"New direct message"), users) dm = messages.dm(self.session, _(u"Direct message to %s") % (screen_name,), _(u"New direct message"), users)
if dm.message.get_response() == widgetUtils.OK: if dm.message.get_response() == widgetUtils.OK:
screen_name = dm.message.get("cb") screen_name = dm.message.get("cb")
user = self.session.get_user_by_screen_name(screen_name) user = self.session.get_user_by_screen_name(screen_name)
event_data = { recipient_id = user
'event': { text = dm.message.get_text()
'type': 'message_create', val = self.session.api_call(call_name="send_direct_message", recipient_id=recipient_id, text=text)
'message_create': {
'target': {
'recipient_id': user,
},
'message_data': {
'text': dm.message.get_text(),
}
}
}
}
val = self.session.api_call(call_name="send_direct_message", **event_data)
if val != None: if val != None:
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db["sent_direct_messages"]["items"].append(val["event"]) self.session.db["sent_direct_messages"].append(val)
else: else:
self.session.db["sent_direct_messages"]["items"].insert(0, val["event"]) self.session.db["sent_direct_messages"].insert(0, val)
pub.sendMessage("sent-dm", data=val["event"], user=self.session.db["user_name"]) pub.sendMessage("sent-dm", data=val, user=self.session.db["user_name"])
if hasattr(dm.message, "destroy"): dm.message.destroy() if hasattr(dm.message, "destroy"): dm.message.destroy()
@_tweets_exist @_tweets_exist
def share_item(self, *args, **kwargs): def share_item(self, *args, **kwargs):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
id = tweet["id"] id = tweet.id
if self.session.settings["general"]["retweet_mode"] == "ask": if self.session.settings["general"]["retweet_mode"] == "ask":
answer = commonMessageDialogs.retweet_question(self.buffer) answer = commonMessageDialogs.retweet_question(self.buffer)
if answer == widgetUtils.YES: if answer == widgetUtils.YES:
@ -488,40 +488,40 @@ class baseBufferController(baseBuffers.buffer):
def _retweet_with_comment(self, tweet, id, comment=''): def _retweet_with_comment(self, tweet, id, comment=''):
# If quoting a retweet, let's quote the original tweet instead the retweet. # If quoting a retweet, let's quote the original tweet instead the retweet.
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
tweet = tweet["retweeted_status"] tweet = tweet.retweeted_status
if "full_text" in tweet: if hasattr(tweet, "full_text"):
comments = tweet["full_text"] comments = tweet.full_text
else: else:
comments = tweet["text"] comments = tweet.text
retweet = messages.tweet(self.session, _(u"Quote"), _(u"Add your comment to the tweet"), u"“@%s: %s" % (tweet["user"]["screen_name"], comments), max=256, messageType="retweet") retweet = messages.tweet(self.session, _(u"Quote"), _(u"Add your comment to the tweet"), u"“@%s: %s" % (tweet.user.screen_name, comments), max=256, messageType="retweet")
if comment != '': if comment != '':
retweet.message.set_text(comment) retweet.message.set_text(comment)
if retweet.message.get_response() == widgetUtils.OK: if retweet.message.get_response() == widgetUtils.OK:
text = retweet.message.get_text() text = retweet.message.get_text()
text = text+" https://twitter.com/{0}/status/{1}".format(tweet["user"]["screen_name"], id) text = text+" https://twitter.com/{0}/status/{1}".format(tweet.user.screen_name, id)
if retweet.image == None: if retweet.image == None:
item = self.session.api_call(call_name="update_status", _sound="retweet_send.ogg", status=text, in_reply_to_status_id=id, tweet_mode="extended") item = self.session.api_call(call_name="update_status", _sound="retweet_send.ogg", status=text, in_reply_to_status_id=id, tweet_mode="extended")
if item != None: if item != None:
new_item = self.session.twitter.show_status(id=item["id"], include_ext_alt_text=True, tweet_mode="extended") new_item = self.session.twitter.get_status(id=item.id, include_ext_alt_text=True, tweet_mode="extended")
pub.sendMessage("sent-tweet", data=new_item, user=self.session.db["user_name"]) pub.sendMessage("sent-tweet", data=new_item, user=self.session.db["user_name"])
else: else:
call_threaded(self.session.api_call, call_name="update_status", _sound="retweet_send.ogg", status=text, media=retweet.image) call_threaded(self.session.api_call, call_name="update_status", _sound="retweet_send.ogg", status=text, media=retweet.image)
if hasattr(retweet.message, "destroy"): retweet.message.destroy() if hasattr(retweet.message, "destroy"): retweet.message.destroy()
def _direct_retweet(self, id): def _direct_retweet(self, id):
item = self.session.api_call(call_name="retweet", _sound="retweet_send.ogg", id=id, tweet_mode="extended") item = self.session.api_call(call_name="retweet", _sound="retweet_send.ogg", id=id)
if item != None: if item != None:
# Retweets are returned as non-extended tweets, so let's get the object as extended # Retweets are returned as non-extended tweets, so let's get the object as extended
# just before sending the event message. See https://github.com/manuelcortez/TWBlue/issues/253 # just before sending the event message. See https://github.com/manuelcortez/TWBlue/issues/253
item = self.session.twitter.show_status(id=item["id"], include_ext_alt_text=True, tweet_mode="extended") item = self.session.twitter.get_status(id=item.id, include_ext_alt_text=True, tweet_mode="extended")
pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"]) pub.sendMessage("sent-tweet", data=item, user=self.session.db["user_name"])
def onFocus(self, *args, **kwargs): def onFocus(self, *args, **kwargs):
tweet = self.get_tweet() tweet = self.get_tweet()
if platform.system() == "Windows" and self.session.settings["general"]["relative_times"] == True: if platform.system() == "Windows" and self.session.settings["general"]["relative_times"] == True:
# fix this: # fix this:
original_date = arrow.get(self.session.db[self.name][self.buffer.list.get_selected()]["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en") original_date = arrow.get(self.session.db[self.name][self.buffer.list.get_selected()].created_at, locale="en")
ts = original_date.humanize(locale=languageHandler.getLanguage()) ts = original_date.humanize(locale=languageHandler.getLanguage())
self.buffer.list.list.SetItem(self.buffer.list.get_selected(), 2, ts) self.buffer.list.list.SetItem(self.buffer.list.get_selected(), 2, ts)
if self.session.settings['sound']['indicate_audio'] and utils.is_audio(tweet): if self.session.settings['sound']['indicate_audio'] and utils.is_audio(tweet):
@ -583,22 +583,22 @@ class baseBufferController(baseBuffers.buffer):
if answer == widgetUtils.YES: if answer == widgetUtils.YES:
try: try:
if self.name == "direct_messages" or self.name == "sent_direct_messages": if self.name == "direct_messages" or self.name == "sent_direct_messages":
self.session.twitter.destroy_direct_message(id=self.get_right_tweet()["id"]) self.session.twitter.destroy_direct_message(id=self.get_right_tweet().id)
self.session.db[self.name]["items"].pop(index) self.session.db[self.name].pop(index)
else: else:
self.session.twitter.destroy_status(id=self.get_right_tweet()["id"]) self.session.twitter.destroy_status(id=self.get_right_tweet().id)
self.session.db[self.name].pop(index) self.session.db[self.name].pop(index)
self.buffer.list.remove_item(index) self.buffer.list.remove_item(index)
except TwythonError: except TweepError:
self.session.sound.play("error.ogg") self.session.sound.play("error.ogg")
@_tweets_exist @_tweets_exist
def user_details(self): def user_details(self):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
if self.type == "dm": if self.type == "dm":
users = [self.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [self.session.get_user(tweet.message_create["sender_id"]).screen_name]
elif self.type == "people": elif self.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
else: else:
users = utils.get_all_users(tweet, self.session.db) users = utils.get_all_users(tweet, self.session.db)
dlg = dialogs.utils.selectUserDialog(title=_(u"User details"), users=users) dlg = dialogs.utils.selectUserDialog(title=_(u"User details"), users=users)
@ -607,70 +607,82 @@ class baseBufferController(baseBuffers.buffer):
if hasattr(dlg, "destroy"): dlg.destroy() if hasattr(dlg, "destroy"): dlg.destroy()
def get_quoted_tweet(self, tweet): def get_quoted_tweet(self, tweet):
quoted_tweet = self.session.twitter.show_status(id=tweet["id"]) quoted_tweet = self.session.twitter.get_status(id=tweet.id)
quoted_tweet["text"] = utils.find_urls_in_text(quoted_tweet["text"], quoted_tweet["entities"]) quoted_tweet.text = utils.find_urls_in_text(quoted_tweet.text, quoted_tweet.entities)
l = tweets.is_long(quoted_tweet) l = tweets.is_long(quoted_tweet)
id = tweets.get_id(l) id = tweets.get_id(l)
original_tweet = self.session.twitter.show_status(id=id) original_tweet = self.session.twitter.get_status(id=id)
original_tweet["text"] = utils.find_urls_in_text(original_tweet["text"], original_tweet["entities"]) original_tweet.text = utils.find_urls_in_text(original_tweet.text, original_tweet.entities)
return compose.compose_quoted_tweet(quoted_tweet, original_tweet, self.session.db, self.session.settings["general"]["relative_times"]) return compose.compose_quoted_tweet(quoted_tweet, original_tweet, self.session.db, self.session.settings["general"]["relative_times"])
def open_in_browser(self, *args, **kwargs): def open_in_browser(self, *args, **kwargs):
tweet = self.get_tweet() tweet = self.get_tweet()
output.speak(_(u"Opening item in web browser...")) output.speak(_(u"Opening item in web browser..."))
url = "https://twitter.com/{screen_name}/status/{tweet_id}".format(screen_name=tweet["user"]["screen_name"], tweet_id=tweet["id"]) url = "https://twitter.com/{screen_name}/status/{tweet_id}".format(screen_name=tweet.user.screen_name, tweet_id=tweet.id)
webbrowser.open(url) webbrowser.open(url)
class directMessagesController(baseBufferController): class directMessagesController(baseBufferController):
def get_more_items(self): def get_more_items(self):
# 50 results are allowed per API call, so let's assume max value can be 50.
# reference: https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/list-events
if self.session.settings["general"]["max_tweets_per_call"] > 50:
count = 50
else:
count = self.session.settings["general"]["max_tweets_per_call"]
total = 0
# try to retrieve the cursor for the current buffer.
cursor = self.session.db["cursors"].get(self.name)
try: try:
items = self.session.get_more_items(self.function, dm=True, name=self.name, count=self.session.settings["general"]["max_tweets_per_call"], cursor=self.session.db[self.name]["cursor"], *self.args, **self.kwargs) items = Cursor(getattr(self.session.twitter, self.function), cursor=cursor, *self.args, **self.kwargs).items(count)
except TwythonError as e: results = [i for i in items]
output.speak(e.message, True) self.session.db["cursors"][self.name] = items.page_iterator.next_cursor
items = results
except TweepError as e:
log.error("Error %s: %s" % (e.api_code, e.reason))
return return
if items == None: if items == None:
return return
sent = [] sent = []
received = []
for i in items: for i in items:
if i["message_create"]["sender_id"] == self.session.db["user_id"]: if int(i.message_create["sender_id"]) == self.session.db["user_id"]:
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db["sent_direct_messages"]["items"].insert(0, i) self.session.db["sent_direct_messages"].insert(0, i)
else:
self.session.db["sent_direct_messages"]["items"].append(i)
sent.append(i) sent.append(i)
else: else:
if self.session.settings["general"]["reverse_timelines"] == False: self.session.db["sent_direct_messages"].append(i)
self.session.db[self.name]["items"].insert(0, i) sent.insert(0, i)
else: else:
self.session.db[self.name]["items"].append(i) if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db[self.name].insert(0, i)
received.append(i)
else:
self.session.db[self.name].append(i)
received.insert(0, i)
total = total+1
pub.sendMessage("more-sent-dms", data=sent, account=self.session.db["user_name"]) pub.sendMessage("more-sent-dms", data=sent, account=self.session.db["user_name"])
selected = self.buffer.list.get_selected() selected = self.buffer.list.get_selected()
if self.session.settings["general"]["reverse_timelines"] == True: if self.session.settings["general"]["reverse_timelines"] == True:
for i in items: for i in received:
if i["message_create"]["sender_id"] == self.session.db["user_id"]: if int(i.message_create["sender_id"]) == self.session.db["user_id"]:
continue continue
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(True, *tweet) self.buffer.list.insert_item(True, *tweet)
self.buffer.list.select_item(selected) self.buffer.list.select_item(selected)
else: else:
for i in items: for i in received:
if i["message_create"]["sender_id"] == self.session.db["user_id"]: if int(i.message_create["sender_id"]) == self.session.db["user_id"]:
continue continue
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(True, *tweet) self.buffer.list.insert_item(True, *tweet)
output.speak(_(u"%s items retrieved") % (len(items)), True) output.speak(_(u"%s items retrieved") % (total), True)
def get_tweet(self):
tweet = self.session.db[self.name]["items"][self.buffer.list.get_selected()]
return tweet
get_right_tweet = get_tweet
@_tweets_exist @_tweets_exist
def reply(self, *args, **kwargs): def reply(self, *args, **kwargs):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
screen_name = self.session.get_user(tweet["message_create"]["sender_id"])["screen_name"] screen_name = self.session.get_user(tweet.message_create["sender_id"]).screen_name
message = messages.reply(self.session, _(u"Mention"), _(u"Mention to %s") % (screen_name,), "@%s " % (screen_name,), [screen_name,]) message = messages.reply(self.session, _(u"Mention"), _(u"Mention to %s") % (screen_name,), "@%s " % (screen_name,), [screen_name,])
if message.message.get_response() == widgetUtils.OK: if message.message.get_response() == widgetUtils.OK:
if config.app["app-settings"]["remember_mention_and_longtweet"]: if config.app["app-settings"]["remember_mention_and_longtweet"]:
@ -688,7 +700,7 @@ class directMessagesController(baseBufferController):
tweet = self.get_tweet() tweet = self.get_tweet()
if platform.system() == "Windows" and self.session.settings["general"]["relative_times"] == True: if platform.system() == "Windows" and self.session.settings["general"]["relative_times"] == True:
# fix this: # fix this:
original_date = arrow.get(int(tweet["created_timestamp"][:-3])) original_date = arrow.get(int(tweet.created_timestamp))
ts = original_date.humanize(locale=languageHandler.getLanguage()) ts = original_date.humanize(locale=languageHandler.getLanguage())
self.buffer.list.list.SetItem(self.buffer.list.get_selected(), 2, ts) self.buffer.list.list.SetItem(self.buffer.list.get_selected(), 2, ts)
if self.session.settings['sound']['indicate_audio'] and utils.is_audio(tweet): if self.session.settings['sound']['indicate_audio'] and utils.is_audio(tweet):
@ -699,15 +711,15 @@ class directMessagesController(baseBufferController):
def clear_list(self): def clear_list(self):
dlg = commonMessageDialogs.clear_list() dlg = commonMessageDialogs.clear_list()
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
self.session.db[self.name]["items"] = [] self.session.db[self.name] = []
self.buffer.list.clear() self.buffer.list.clear()
def auto_read(self, number_of_items): def auto_read(self, number_of_items):
if number_of_items == 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False: if number_of_items == 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False:
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
tweet = self.session.db[self.name]["items"][-1] tweet = self.session.db[self.name][-1]
else: else:
tweet = self.session.db[self.name]["items"][0] tweet = self.session.db[self.name][0]
output.speak(_(u"New direct message")) output.speak(_(u"New direct message"))
output.speak(" ".join(self.compose_function(tweet, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session))) output.speak(" ".join(self.compose_function(tweet, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)))
elif number_of_items > 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False: elif number_of_items > 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False:
@ -721,7 +733,7 @@ class sentDirectMessagesController(directMessagesController):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(sentDirectMessagesController, self).__init__(*args, **kwargs) super(sentDirectMessagesController, self).__init__(*args, **kwargs)
if ("sent_direct_messages" in self.session.db) == False: if ("sent_direct_messages" in self.session.db) == False:
self.session.db["sent_direct_messages"] = {"items": []} self.session.db["sent_direct_messages"] = []
def get_more_items(self): def get_more_items(self):
output.speak(_(u"Getting more items cannot be done in this buffer. Use the direct messages buffer instead.")) output.speak(_(u"Getting more items cannot be done in this buffer. Use the direct messages buffer instead."))
@ -733,11 +745,11 @@ class sentDirectMessagesController(directMessagesController):
if self.session.settings["general"]["reverse_timelines"] == True: if self.session.settings["general"]["reverse_timelines"] == True:
for i in items: for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(True, *tweet) self.buffer.list.insert_item(False, *tweet)
else: else:
for i in items: for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(True, *tweet) self.buffer.list.insert_item(False, *tweet)
class listBufferController(baseBufferController): class listBufferController(baseBufferController):
def __init__(self, parent, function, name, sessionObject, account, sound=None, bufferType=None, list_id=None, *args, **kwargs): def __init__(self, parent, function, name, sessionObject, account, sound=None, bufferType=None, list_id=None, *args, **kwargs):
@ -751,13 +763,9 @@ class listBufferController(baseBufferController):
super(listBufferController, self).start_stream(mandatory, play_sound, avoid_autoreading) super(listBufferController, self).start_stream(mandatory, play_sound, avoid_autoreading)
def get_user_ids(self): def get_user_ids(self):
next_cursor = -1 for i in Cursor(self.session.twitter.list_members, list_id=self.list_id, include_entities=False, skip_status=True).items():
while(next_cursor): if i.id not in self.users:
users = self.session.twitter.get_list_members(list_id=self.list_id, cursor=next_cursor, include_entities=False, skip_status=True) self.users.append(i.id)
for i in users['users']:
if i["id"] not in self.users:
self.users.append(i["id"])
next_cursor = users["next_cursor"]
def remove_buffer(self, force=False): def remove_buffer(self, force=False):
if force == False: if force == False:
@ -837,7 +845,7 @@ class peopleBufferController(baseBufferController):
@_tweets_exist @_tweets_exist
def reply(self, *args, **kwargs): def reply(self, *args, **kwargs):
tweet = self.get_right_tweet() tweet = self.get_right_tweet()
screen_name = tweet["screen_name"] screen_name = tweet.screen_name
message = messages.reply(self.session, _(u"Mention"), _(u"Mention to %s") % (screen_name,), "@%s " % (screen_name,), [screen_name,]) message = messages.reply(self.session, _(u"Mention"), _(u"Mention to %s") % (screen_name,), "@%s " % (screen_name,), [screen_name,])
if message.message.get_response() == widgetUtils.OK: if message.message.get_response() == widgetUtils.OK:
if config.app["app-settings"]["remember_mention_and_longtweet"]: if config.app["app-settings"]["remember_mention_and_longtweet"]:
@ -858,31 +866,48 @@ class peopleBufferController(baseBufferController):
self.execution_time = current_time self.execution_time = current_time
log.debug("Starting stream for %s buffer, %s account" % (self.name, self.account,)) log.debug("Starting stream for %s buffer, %s account" % (self.name, self.account,))
log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs)) log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs))
val = self.session.get_cursored_stream(self.name, self.function, *self.args, **self.kwargs) # try to retrieve the cursor for the current buffer.
cursor = self.session.db["cursors"].get(self.name)
try:
# We need to assign all results somewhere else so the cursor variable would b generated.
val = Cursor(getattr(self.session.twitter, self.function), *self.args, **self.kwargs).items(self.session.settings["general"]["max_tweets_per_call"])
results = [i for i in val]
self.session.db["cursors"][self.name] = val.page_iterator.next_cursor
val = results
val.reverse()
except TweepError as e:
log.error("Error %s: %s" % (e.api_code, e.reason))
return
number_of_items = self.session.order_people(self.name, val)
log.debug("Number of items retrieved: %d" % (number_of_items,))
self.put_items_on_list(val) self.put_items_on_list(val)
if hasattr(self, "finished_timeline") and self.finished_timeline == False: if hasattr(self, "finished_timeline") and self.finished_timeline == False:
self.username = self.session.api_call("show_user", **self.kwargs)["screen_name"] self.username = self.session.api_call("get_user", **self.kwargs).screen_name
self.finished_timeline = True self.finished_timeline = True
if val > 0 and self.sound != None and self.session.settings["sound"]["session_mute"] == False and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and play_sound == True: if number_of_items > 0 and self.sound != None and self.session.settings["sound"]["session_mute"] == False and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and play_sound == True:
self.session.sound.play(self.sound) self.session.sound.play(self.sound)
# Autoread settings # Autoread settings
if avoid_autoreading == False and mandatory == True and val > 0 and self.name in self.session.settings["other_buffers"]["autoread_buffers"]: if avoid_autoreading == False and mandatory == True and val > 0 and self.name in self.session.settings["other_buffers"]["autoread_buffers"]:
self.auto_read(val) self.auto_read(number_of_items)
return val return number_of_items
def get_more_items(self): def get_more_items(self):
try: 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"], *self.args, **self.kwargs) cursor = self.session.db["cursors"].get(self.name)
except TwythonError as e: items = Cursor(getattr(self.session.twitter, self.function), users=True, cursor=cursor, *self.args, **self.kwargs).items(self.session.settings["general"]["max_tweets_per_call"])
output.speak(e.message, True) results = [i for i in items]
self.session.db["cursors"][self.name] = items.page_iterator.next_cursor
items = results
except TweepError as e:
log.error("Error %s: %s" % (e.api_code, e.reason))
return return
if items == None: if items == None:
return return
for i in items: for i in items:
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db[self.name]["items"].insert(0, i) self.session.db[self.name].insert(0, i)
else: else:
self.session.db[self.name]["items"].append(i) self.session.db[self.name].append(i)
selected = self.buffer.list.get_selected() selected = self.buffer.list.get_selected()
if self.session.settings["general"]["reverse_timelines"] == True: if self.session.settings["general"]["reverse_timelines"] == True:
for i in items: for i in items:
@ -899,18 +924,18 @@ class peopleBufferController(baseBufferController):
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,))
if self.buffer.list.get_count() == 0: if self.buffer.list.get_count() == 0:
for i in self.session.db[self.name]["items"]: for i in self.session.db[self.name]:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session) tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session)
self.buffer.list.insert_item(False, *tweet) self.buffer.list.insert_item(False, *tweet)
self.buffer.set_position(self.session.settings["general"]["reverse_timelines"]) self.buffer.set_position(self.session.settings["general"]["reverse_timelines"])
# self.buffer.set_list_position() # self.buffer.set_list_position()
elif self.buffer.list.get_count() > 0: elif self.buffer.list.get_count() > 0:
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"][len(self.session.db[self.name]["items"])-number_of_items:]: for i in self.session.db[self.name][len(self.session.db[self.name])-number_of_items:]:
tweet = self.compose_function(i, self.session.db) tweet = self.compose_function(i, self.session.db)
self.buffer.list.insert_item(False, *tweet) self.buffer.list.insert_item(False, *tweet)
else: else:
items = self.session.db[self.name]["items"][0:number_of_items] items = self.session.db[self.name][0:number_of_items]
items.reverse() items.reverse()
for i in items: for i in items:
tweet = self.compose_function(i, self.session.db) tweet = self.compose_function(i, self.session.db)
@ -918,7 +943,7 @@ class peopleBufferController(baseBufferController):
log.debug("now the list contains %d items" % (self.buffer.list.get_count(),)) log.debug("now the list contains %d items" % (self.buffer.list.get_count(),))
def get_right_tweet(self): def get_right_tweet(self):
tweet = self.session.db[self.name]["items"][self.buffer.list.get_selected()] tweet = self.session.db[self.name][self.buffer.list.get_selected()]
return tweet return tweet
def add_new_item(self, item): def add_new_item(self, item):
@ -933,12 +958,12 @@ class peopleBufferController(baseBufferController):
def clear_list(self): def clear_list(self):
dlg = commonMessageDialogs.clear_list() dlg = commonMessageDialogs.clear_list()
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
self.session.db[self.name]["items"] = [] self.session.db[self.name] = []
self.session.db[self.name]["cursor"] = -1 self.session.db["cursors"][self.name] = -1
self.buffer.list.clear() self.buffer.list.clear()
def interact(self): def interact(self):
user.profileController(self.session, user=self.get_right_tweet()["screen_name"]) user.profileController(self.session, user=self.get_right_tweet().screen_name)
def show_menu(self, ev, pos=0, *args, **kwargs): def show_menu(self, ev, pos=0, *args, **kwargs):
menu = menus.peoplePanelMenu() menu = menus.peoplePanelMenu()
@ -961,9 +986,9 @@ class peopleBufferController(baseBufferController):
def auto_read(self, number_of_items): def auto_read(self, number_of_items):
if number_of_items == 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False: if number_of_items == 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False:
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
tweet = self.session.db[self.name]["items"][-1] tweet = self.session.db[self.name][-1]
else: else:
tweet = self.session.db[self.name["items"]][0] tweet = self.session.db[self.name][0]
output.speak(" ".join(self.compose_function(tweet, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session))) output.speak(" ".join(self.compose_function(tweet, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)))
elif number_of_items > 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False: elif number_of_items > 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False:
output.speak(_(u"{0} new followers.").format(number_of_items)) output.speak(_(u"{0} new followers.").format(number_of_items))
@ -971,7 +996,7 @@ class peopleBufferController(baseBufferController):
def open_in_browser(self, *args, **kwargs): def open_in_browser(self, *args, **kwargs):
tweet = self.get_tweet() tweet = self.get_tweet()
output.speak(_(u"Opening item in web browser...")) output.speak(_(u"Opening item in web browser..."))
url = "https://twitter.com/{screen_name}".format(screen_name=tweet["screen_name"]) url = "https://twitter.com/{screen_name}".format(screen_name=tweet.screen_name)
webbrowser.open(url) webbrowser.open(url)
class searchBufferController(baseBufferController): class searchBufferController(baseBufferController):
@ -1011,41 +1036,6 @@ class searchBufferController(baseBufferController):
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
return False return False
def get_more_items(self):
elements = []
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][-1]["id"]
try:
items = self.session.search(self.name, 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, True)
if items == None:
return
for i in items:
if utils.is_allowed(i, self.session.settings, self.name) == True and utils.find_item(i["id"], self.session.db[self.name]) == None:
i = self.session.check_quoted_status(i)
i = self.session.check_long_tweet(i)
elements.append(i)
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()
if self.session.settings["general"]["reverse_timelines"] == False:
for i in elements:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(True, *tweet)
else:
for i in items:
tweet = self.compose_function(i, self.session.db, self.session.settings["general"]["relative_times"], self.session.settings["general"]["show_screen_names"], self.session)
self.buffer.list.insert_item(False, *tweet)
# self.buffer.list.select_item(selection+elements)
# else:
self.buffer.list.select_item(selection)
output.speak(_(u"%s items retrieved") % (str(len(elements))), True)
class searchPeopleBufferController(peopleBufferController): class searchPeopleBufferController(peopleBufferController):
def __init__(self, parent, function, name, sessionObject, account, bufferType="peoplePanel", *args, **kwargs): def __init__(self, parent, function, name, sessionObject, account, bufferType="peoplePanel", *args, **kwargs):
@ -1085,16 +1075,16 @@ class searchPeopleBufferController(peopleBufferController):
self.kwargs["page"] += 1 self.kwargs["page"] += 1
try: try:
items = self.session.get_more_items(self.function, users=True, name=self.name, count=self.session.settings["general"]["max_tweets_per_call"], *self.args, **self.kwargs) items = self.session.get_more_items(self.function, users=True, name=self.name, count=self.session.settings["general"]["max_tweets_per_call"], *self.args, **self.kwargs)
except TwythonError as e: except TweepError as e:
output.speak(e.message, True) output.speak(e.reason, True)
return return
if items == None: if items == None:
return return
for i in items: for i in items:
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
self.session.db[self.name]["items"].insert(0, i) self.session.db[self.name].insert(0, i)
else: else:
self.session.db[self.name]["items"].append(i) self.session.db[self.name].append(i)
selected = self.buffer.list.get_selected() selected = self.buffer.list.get_selected()
# self.put_items_on_list(len(items)) # self.put_items_on_list(len(items))
if self.session.settings["general"]["reverse_timelines"] == True: if self.session.settings["general"]["reverse_timelines"] == True:
@ -1151,9 +1141,9 @@ class trendsBufferController(baseBuffers.buffer):
if self.execution_time == 0 or current_time-self.execution_time >= 180 or mandatory == True: if self.execution_time == 0 or current_time-self.execution_time >= 180 or mandatory == True:
self.execution_time = current_time self.execution_time = current_time
try: try:
data = self.session.call_paged("get_place_trends", id=self.trendsFor) data = self.session.twitter.trends_place(id=self.trendsFor)
except: except TweepError as err:
return log.error("Error %s: %s" % (err.api_code, err.reason))
if not hasattr(self, "name_"): if not hasattr(self, "name_"):
self.name_ = data[0]["locations"][0]["name"] self.name_ = data[0]["locations"][0]["name"]
self.trends = data[0]["trends"] self.trends = data[0]["trends"]
@ -1262,23 +1252,23 @@ class conversationBufferController(searchBufferController):
self.statuses = [] self.statuses = []
self.ids = [] self.ids = []
self.statuses.append(self.tweet) self.statuses.append(self.tweet)
self.ids.append(self.tweet["id"]) self.ids.append(self.tweet.id)
tweet = self.tweet tweet = self.tweet
while tweet["in_reply_to_status_id"] != None: while tweet.in_reply_to_status_id != None:
try: try:
tweet = self.session.twitter.show_status(id=tweet["in_reply_to_status_id"], tweet_mode="extended") tweet = self.session.twitter.get_status(id=tweet.in_reply_to_status_id, tweet_mode="extended")
except TwythonError as err: except TweepError as err:
break break
self.statuses.insert(0, tweet) self.statuses.insert(0, tweet)
self.ids.append(tweet["id"]) self.ids.append(tweet.id)
if tweet["in_reply_to_status_id"] == None: if tweet.in_reply_to_status_id == None:
self.kwargs["since_id"] = tweet["id"] self.kwargs["since_id"] = tweet.id
self.ids.append(tweet["id"]) self.ids.append(tweet.id)
val2 = self.session.search(self.name, tweet_mode="extended", *self.args, **self.kwargs) val2 = self.session.search(self.name, tweet_mode="extended", *self.args, **self.kwargs)
for i in val2: for i in val2:
if i["in_reply_to_status_id"] in self.ids: if i.in_reply_to_status_id in self.ids:
self.statuses.append(i) self.statuses.append(i)
self.ids.append(i["id"]) self.ids.append(i.id)
tweet = i tweet = i
number_of_items = self.session.order_buffer(self.name, self.statuses) number_of_items = self.session.order_buffer(self.name, self.statuses)
log.debug("Number of items retrieved: %d" % (number_of_items,)) log.debug("Number of items retrieved: %d" % (number_of_items,))

View File

@ -1,13 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from builtins import object
import widgetUtils import widgetUtils
import output import output
import logging
from wxUI.dialogs import lists from wxUI.dialogs import lists
from twython import TwythonError from tweepy.error import TweepError
from sessions.twitter import compose, utils from sessions.twitter import compose, utils
from pubsub import pub from pubsub import pub
log = logging.getLogger("controller.listsController")
class listsController(object): class listsController(object):
def __init__(self, session, user=None): def __init__(self, session, user=None):
super(listsController, self).__init__() super(listsController, self).__init__()
@ -31,7 +32,7 @@ class listsController(object):
return [compose.compose_list(item) for item in self.session.db["lists"]] return [compose.compose_list(item) for item in self.session.db["lists"]]
def get_user_lists(self, user): def get_user_lists(self, user):
self.lists = self.session.twitter.show_lists(reverse=True, screen_name=user) self.lists = self.session.twitter.lists_all(reverse=True, screen_name=user)
return [compose.compose_list(item) for item in self.lists] return [compose.compose_list(item) for item in self.lists]
def create_list(self, *args, **kwargs): def create_list(self, *args, **kwargs):
@ -48,8 +49,9 @@ class listsController(object):
new_list = self.session.twitter.create_list(name=name, description=description, mode=mode) new_list = self.session.twitter.create_list(name=name, description=description, mode=mode)
self.session.db["lists"].append(new_list) self.session.db["lists"].append(new_list)
self.dialog.lista.insert_item(False, *compose.compose_list(new_list)) self.dialog.lista.insert_item(False, *compose.compose_list(new_list))
except TwythonError as e: except TweepError as e:
output.speak("error %s: %s" % (e.status_code, e.msg)) output.speak("error %s: %s" % (e.api_code, e.reason))
log.exception("error %s: %s" % (e.api_code, e.reason))
dialog.destroy() dialog.destroy()
def edit_list(self, *args, **kwargs): def edit_list(self, *args, **kwargs):
@ -65,44 +67,44 @@ class listsController(object):
else: else:
mode = "private" mode = "private"
try: try:
self.session.twitter.update_list(list_id=list["id"], name=name, description=description, mode=mode) self.session.twitter.update_list(list_id=list.id, name=name, description=description, mode=mode)
self.session.get_lists() self.session.get_lists()
self.dialog.populate_list(self.get_all_lists(), True) self.dialog.populate_list(self.get_all_lists(), True)
except TwythonError as e: except TweepError as e:
output.speak("error %s: %s" % (e.error_code, e.msg)) output.speak("error %s: %s" % (e.api_code, e.reason))
dialog.destroy() dialog.destroy()
def remove_list(self, *args, **kwargs): def remove_list(self, *args, **kwargs):
if self.dialog.lista.get_count() == 0: return if self.dialog.lista.get_count() == 0: return
list = self.session.db["lists"][self.dialog.get_item()]["id"] list = self.session.db["lists"][self.dialog.get_item()].id
if lists.remove_list() == widgetUtils.YES: if lists.remove_list() == widgetUtils.YES:
try: try:
self.session.twitter.delete_list(list_id=list) self.session.twitter.destroy_list(list_id=list)
self.session.db["lists"].pop(self.dialog.get_item()) self.session.db["lists"].pop(self.dialog.get_item())
self.dialog.lista.remove_item(self.dialog.get_item()) self.dialog.lista.remove_item(self.dialog.get_item())
except TwythonError as e: except TweepError as e:
output.speak("error %s: %s" % (e.error_code, e.msg)) output.speak("error %s: %s" % (e.api_code, e.reason))
def open_list_as_buffer(self, *args, **kwargs): def open_list_as_buffer(self, *args, **kwargs):
if self.dialog.lista.get_count() == 0: return if self.dialog.lista.get_count() == 0: return
list = self.session.db["lists"][self.dialog.get_item()] list = self.session.db["lists"][self.dialog.get_item()]
pub.sendMessage("create-new-buffer", buffer="list", account=self.session.db["user_name"], create=list["name"]) pub.sendMessage("create-new-buffer", buffer="list", account=self.session.db["user_name"], create=list.name)
def subscribe(self, *args, **kwargs): def subscribe(self, *args, **kwargs):
if self.dialog.lista.get_count() == 0: return if self.dialog.lista.get_count() == 0: return
list_id = self.lists[self.dialog.get_item()]["id"] list_id = self.lists[self.dialog.get_item()].id
try: try:
list = self.session.twitter.subscribe_to_list(list_id=list_id) list = self.session.twitter.subscribe_list(list_id=list_id)
item = utils.find_item(list["id"], self.session.db["lists"]) item = utils.find_item(list.id, self.session.db["lists"])
self.session.db["lists"].append(list) self.session.db["lists"].append(list)
except TwythonError as e: except TweepError as e:
output.speak("error %s: %s" % (e.status_code, e.msg)) output.speak("error %s: %s" % (e.api_code, e.reason))
def unsubscribe(self, *args, **kwargs): def unsubscribe(self, *args, **kwargs):
if self.dialog.lista.get_count() == 0: return if self.dialog.lista.get_count() == 0: return
list_id = self.lists[self.dialog.get_item()]["id"] list_id = self.lists[self.dialog.get_item()].id
try: try:
list = self.session.twitter.unsubscribe_from_list(list_id=list_id) list = self.session.twitter.unsubscribe_list(list_id=list_id)
self.session.db["lists"].remove(list) self.session.db["lists"].remove(list)
except TwythonError as e: except TweepError as e:
output.speak("error %s: %s" % (e.status_code, e.msg)) output.speak("error %s: %s" % (e.api_code, e.reason))

View File

@ -1,8 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from builtins import str
from builtins import range
from builtins import object
import platform import platform
system = platform.system() system = platform.system()
import application import application
@ -34,7 +30,7 @@ from sessions.twitter import session as session_
from pubsub import pub from pubsub import pub
import sound import sound
import output import output
from twython import TwythonError, TwythonAuthError from tweepy.error import TweepError
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
from mysc.repeating_timer import RepeatingTimer from mysc.repeating_timer import RepeatingTimer
from mysc import restart from mysc import restart
@ -304,15 +300,15 @@ class Controller(object):
self.view.add_buffer(account.buffer , name=session.db["user_name"]) self.view.add_buffer(account.buffer , name=session.db["user_name"])
for i in session.settings['general']['buffer_order']: for i in session.settings['general']['buffer_order']:
if i == 'home': if i == 'home':
home = twitterBuffers.baseBufferController(self.view.nb, "get_home_timeline", "home_timeline", session, session.db["user_name"], sound="tweet_received.ogg", tweet_mode="extended") home = twitterBuffers.baseBufferController(self.view.nb, "home_timeline", "home_timeline", session, session.db["user_name"], sound="tweet_received.ogg", tweet_mode="extended")
self.buffers.append(home) self.buffers.append(home)
self.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'mentions': elif i == 'mentions':
mentions = twitterBuffers.baseBufferController(self.view.nb, "get_mentions_timeline", "mentions", session, session.db["user_name"], sound="mention_received.ogg", tweet_mode="extended") mentions = twitterBuffers.baseBufferController(self.view.nb, "mentions_timeline", "mentions", session, session.db["user_name"], sound="mention_received.ogg", tweet_mode="extended")
self.buffers.append(mentions) self.buffers.append(mentions)
self.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'dm': elif i == 'dm':
dm = twitterBuffers.directMessagesController(self.view.nb, "get_direct_messages", "direct_messages", session, session.db["user_name"], bufferType="dmPanel", compose_func="compose_direct_message", sound="dm_received.ogg", full_text=True, items="events") dm = twitterBuffers.directMessagesController(self.view.nb, "list_direct_messages", "direct_messages", session, session.db["user_name"], bufferType="dmPanel", compose_func="compose_direct_message", sound="dm_received.ogg", full_text=True, items="events")
self.buffers.append(dm) self.buffers.append(dm)
self.view.insert_buffer(dm.buffer, name=_(u"Direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(dm.buffer, name=_(u"Direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'sent_dm': elif i == 'sent_dm':
@ -320,62 +316,62 @@ class Controller(object):
self.buffers.append(sent_dm) self.buffers.append(sent_dm)
self.view.insert_buffer(sent_dm.buffer, name=_(u"Sent direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(sent_dm.buffer, name=_(u"Sent direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'sent_tweets': elif i == 'sent_tweets':
sent_tweets = twitterBuffers.baseBufferController(self.view.nb, "get_user_timeline", "sent_tweets", session, session.db["user_name"], screen_name=session.db["user_name"], tweet_mode="extended") sent_tweets = twitterBuffers.baseBufferController(self.view.nb, "user_timeline", "sent_tweets", session, session.db["user_name"], screen_name=session.db["user_name"], tweet_mode="extended")
self.buffers.append(sent_tweets) self.buffers.append(sent_tweets)
self.view.insert_buffer(sent_tweets.buffer, name=_(u"Sent tweets"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(sent_tweets.buffer, name=_(u"Sent tweets"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'favorites': elif i == 'favorites':
favourites = twitterBuffers.baseBufferController(self.view.nb, "get_favorites", "favourites", session, session.db["user_name"], sound="favourite.ogg", tweet_mode="extended") favourites = twitterBuffers.baseBufferController(self.view.nb, "favorites", "favourites", session, session.db["user_name"], sound="favourite.ogg", tweet_mode="extended")
self.buffers.append(favourites) self.buffers.append(favourites)
self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'followers': elif i == 'followers':
followers = twitterBuffers.peopleBufferController(self.view.nb, "get_followers_list", "followers", session, session.db["user_name"], sound="update_followers.ogg", screen_name=session.db["user_name"]) followers = twitterBuffers.peopleBufferController(self.view.nb, "followers", "followers", session, session.db["user_name"], sound="update_followers.ogg", screen_name=session.db["user_name"])
self.buffers.append(followers) self.buffers.append(followers)
self.view.insert_buffer(followers.buffer, name=_(u"Followers"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(followers.buffer, name=_(u"Followers"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'friends': elif i == 'friends':
friends = twitterBuffers.peopleBufferController(self.view.nb, "get_friends_list", "friends", session, session.db["user_name"], screen_name=session.db["user_name"]) friends = twitterBuffers.peopleBufferController(self.view.nb, "friends", "friends", session, session.db["user_name"], screen_name=session.db["user_name"])
self.buffers.append(friends) self.buffers.append(friends)
self.view.insert_buffer(friends.buffer, name=_(u"Friends"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(friends.buffer, name=_(u"Friends"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'blocks': elif i == 'blocks':
blocks = twitterBuffers.peopleBufferController(self.view.nb, "list_blocks", "blocked", session, session.db["user_name"]) blocks = twitterBuffers.peopleBufferController(self.view.nb, "blocks", "blocked", session, session.db["user_name"])
self.buffers.append(blocks) self.buffers.append(blocks)
self.view.insert_buffer(blocks.buffer, name=_(u"Blocked users"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(blocks.buffer, name=_(u"Blocked users"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
elif i == 'muted': elif i == 'muted':
muted = twitterBuffers.peopleBufferController(self.view.nb, "list_mutes", "muted", session, session.db["user_name"]) muted = twitterBuffers.peopleBufferController(self.view.nb, "mutes", "muted", session, session.db["user_name"])
self.buffers.append(muted) self.buffers.append(muted)
self.view.insert_buffer(muted.buffer, name=_(u"Muted users"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(muted.buffer, name=_(u"Muted users"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
timelines = baseBuffers.emptyPanel(self.view.nb, "timelines", session.db["user_name"]) timelines = baseBuffers.emptyPanel(self.view.nb, "timelines", session.db["user_name"])
self.buffers.append(timelines) self.buffers.append(timelines)
self.view.insert_buffer(timelines.buffer , name=_(u"Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(timelines.buffer , name=_(u"Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["timelines"]: for i in session.settings["other_buffers"]["timelines"]:
tl = twitterBuffers.baseBufferController(self.view.nb, "get_user_timeline", "%s-timeline" % (i,), session, session.db["user_name"], sound="tweet_timeline.ogg", bufferType=None, user_id=i, tweet_mode="extended") tl = twitterBuffers.baseBufferController(self.view.nb, "user_timeline", "%s-timeline" % (i,), session, session.db["user_name"], sound="tweet_timeline.ogg", bufferType=None, user_id=i, tweet_mode="extended")
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(i,), pos=self.view.search("timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(i,), pos=self.view.search("timelines", session.db["user_name"]))
favs_timelines = baseBuffers.emptyPanel(self.view.nb, "favs_timelines", session.db["user_name"]) favs_timelines = baseBuffers.emptyPanel(self.view.nb, "favs_timelines", session.db["user_name"])
self.buffers.append(favs_timelines) self.buffers.append(favs_timelines)
self.view.insert_buffer(favs_timelines.buffer , name=_(u"Likes timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(favs_timelines.buffer , name=_(u"Likes timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["favourites_timelines"]: for i in session.settings["other_buffers"]["favourites_timelines"]:
tl = twitterBuffers.baseBufferController(self.view.nb, "get_favorites", "%s-favorite" % (i,), session, session.db["user_name"], bufferType=None, sound="favourites_timeline_updated.ogg", user_id=i, tweet_mode="extended") tl = twitterBuffers.baseBufferController(self.view.nb, "favorites", "%s-favorite" % (i,), session, session.db["user_name"], bufferType=None, sound="favourites_timeline_updated.ogg", user_id=i, tweet_mode="extended")
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Likes for {}").format(i,), pos=self.view.search("favs_timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Likes for {}").format(i,), pos=self.view.search("favs_timelines", session.db["user_name"]))
followers_timelines = baseBuffers.emptyPanel(self.view.nb, "followers_timelines", session.db["user_name"]) followers_timelines = baseBuffers.emptyPanel(self.view.nb, "followers_timelines", session.db["user_name"])
self.buffers.append(followers_timelines) self.buffers.append(followers_timelines)
self.view.insert_buffer(followers_timelines.buffer , name=_(u"Followers' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(followers_timelines.buffer , name=_(u"Followers' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["followers_timelines"]: for i in session.settings["other_buffers"]["followers_timelines"]:
tl = twitterBuffers.peopleBufferController(self.view.nb, "get_followers_list", "%s-followers" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i) tl = twitterBuffers.peopleBufferController(self.view.nb, "followers", "%s-followers" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i)
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Followers for {}").format(i,), pos=self.view.search("followers_timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Followers for {}").format(i,), pos=self.view.search("followers_timelines", session.db["user_name"]))
friends_timelines = baseBuffers.emptyPanel(self.view.nb, "friends_timelines", session.db["user_name"]) friends_timelines = baseBuffers.emptyPanel(self.view.nb, "friends_timelines", session.db["user_name"])
self.buffers.append(friends_timelines) self.buffers.append(friends_timelines)
self.view.insert_buffer(friends_timelines.buffer , name=_(u"Friends' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(friends_timelines.buffer , name=_(u"Friends' Timelines"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["friends_timelines"]: for i in session.settings["other_buffers"]["friends_timelines"]:
tl = twitterBuffers.peopleBufferController(self.view.nb, "get_friends_list", "%s-friends" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i) tl = twitterBuffers.peopleBufferController(self.view.nb, "friends", "%s-friends" % (i,), session, session.db["user_name"], sound="new_event.ogg", user_id=i)
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"Friends for {}").format(i,), pos=self.view.search("friends_timelines", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"Friends for {}").format(i,), pos=self.view.search("friends_timelines", session.db["user_name"]))
lists = baseBuffers.emptyPanel(self.view.nb, "lists", session.db["user_name"]) lists = baseBuffers.emptyPanel(self.view.nb, "lists", session.db["user_name"])
self.buffers.append(lists) self.buffers.append(lists)
self.view.insert_buffer(lists.buffer , name=_(u"Lists"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) self.view.insert_buffer(lists.buffer , name=_(u"Lists"), pos=self.view.search(session.db["user_name"], session.db["user_name"]))
for i in session.settings["other_buffers"]["lists"]: for i in session.settings["other_buffers"]["lists"]:
tl = twitterBuffers.listBufferController(self.view.nb, "get_list_statuses", "%s-list" % (i,), session, session.db["user_name"], bufferType=None, sound="list_tweet.ogg", list_id=utils.find_list(i, session.db["lists"]), tweet_mode="extended") tl = twitterBuffers.listBufferController(self.view.nb, "list_timeline", "%s-list" % (i,), session, session.db["user_name"], bufferType=None, sound="list_tweet.ogg", list_id=utils.find_list(i, session.db["lists"]), tweet_mode="extended")
session.lists.append(tl) session.lists.append(tl)
self.buffers.append(tl) self.buffers.append(tl)
self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(i), pos=self.view.search("lists", session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(i), pos=self.view.search("lists", session.db["user_name"]))
@ -530,9 +526,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
dlg = dialogs.utils.selectUserDialog(_(u"Select the user"), users) dlg = dialogs.utils.selectUserDialog(_(u"Select the user"), users)
@ -547,9 +543,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
dlg = dialogs.utils.selectUserDialog(_(u"Select the user"), users) dlg = dialogs.utils.selectUserDialog(_(u"Select the user"), users)
@ -561,23 +557,23 @@ class Controller(object):
dlg.populate_list([compose.compose_list(item) for item in buff.session.db["lists"]]) dlg.populate_list([compose.compose_list(item) for item in buff.session.db["lists"]])
if dlg.get_response() == widgetUtils.OK: if dlg.get_response() == widgetUtils.OK:
try: try:
list = buff.session.twitter.add_list_member(list_id=buff.session.db["lists"][dlg.get_item()]["id"], screen_name=user) list = buff.session.twitter.add_list_member(list_id=buff.session.db["lists"][dlg.get_item()].id, screen_name=user)
older_list = utils.find_item(buff.session.db["lists"][dlg.get_item()]["id"], buff.session.db["lists"]) older_list = utils.find_item(buff.session.db["lists"][dlg.get_item()].id, buff.session.db["lists"])
listBuffer = self.search_buffer("%s-list" % (buff.session.db["lists"][dlg.get_item()]["name"].lower()), buff.session.db["user_name"]) listBuffer = self.search_buffer("%s-list" % (buff.session.db["lists"][dlg.get_item()].name.lower()), buff.session.db["user_name"])
if listBuffer != None: listBuffer.get_user_ids() if listBuffer != None: listBuffer.get_user_ids()
buff.session.db["lists"].pop(older_list) buff.session.db["lists"].pop(older_list)
buff.session.db["lists"].append(list) buff.session.db["lists"].append(list)
except TwythonError as e: except TweepError as e:
output.speak("error %s: %s" % (e.error_code, e.msg)) output.speak("error %s: %s" % (e.api_code, e.reason))
def remove_from_list(self, *args, **kwargs): def remove_from_list(self, *args, **kwargs):
buff = self.get_best_buffer() buff = self.get_best_buffer()
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
dlg = dialogs.utils.selectUserDialog(_(u"Select the user"), users) dlg = dialogs.utils.selectUserDialog(_(u"Select the user"), users)
@ -589,14 +585,14 @@ class Controller(object):
dlg.populate_list([compose.compose_list(item) for item in buff.session.db["lists"]]) dlg.populate_list([compose.compose_list(item) for item in buff.session.db["lists"]])
if dlg.get_response() == widgetUtils.OK: if dlg.get_response() == widgetUtils.OK:
try: try:
list = buff.session.twitter.delete_list_member(list_id=buff.session.db["lists"][dlg.get_item()]["id"], screen_name=user) list = buff.session.twitter.remove_list_member(list_id=buff.session.db["lists"][dlg.get_item()].id, screen_name=user)
older_list = utils.find_item(buff.session.db["lists"][dlg.get_item()]["id"], buff.session.db["lists"]) older_list = utils.find_item(buff.session.db["lists"][dlg.get_item()].id, buff.session.db["lists"])
listBuffer = self.search_buffer("%s-list" % (buff.session.db["lists"][dlg.get_item()]["name"].lower()), buff.session.db["user_name"]) listBuffer = self.search_buffer("%s-list" % (buff.session.db["lists"][dlg.get_item()].name.lower()), buff.session.db["user_name"])
if listBuffer != None: listBuffer.get_user_ids() if listBuffer != None: listBuffer.get_user_ids()
buff.session.db["lists"].pop(older_list) buff.session.db["lists"].pop(older_list)
buff.session.db["lists"].append(list) buff.session.db["lists"].append(list)
except TwythonError as e: except TweepError as e:
output.speak("error %s: %s" % (e.error_code, e.msg)) output.speak("error %s: %s" % (e.api_code, e.reason))
def list_manager(self, *args, **kwargs): def list_manager(self, *args, **kwargs):
s = self.get_best_buffer().session s = self.get_best_buffer().session
@ -669,9 +665,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
u = userActionsController.userActionsController(buff, users) u = userActionsController.userActionsController(buff, users)
@ -681,9 +677,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
u = userActionsController.userActionsController(buff, users, "unfollow") u = userActionsController.userActionsController(buff, users, "unfollow")
@ -693,9 +689,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
u = userActionsController.userActionsController(buff, users, "mute") u = userActionsController.userActionsController(buff, users, "mute")
@ -705,9 +701,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
u = userActionsController.userActionsController(buff, users, "unmute") u = userActionsController.userActionsController(buff, users, "unmute")
@ -717,9 +713,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
u = userActionsController.userActionsController(buff, users, "block") u = userActionsController.userActionsController(buff, users, "block")
@ -729,9 +725,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
u = userActionsController.userActionsController(buff, users, "unblock") u = userActionsController.userActionsController(buff, users, "unblock")
@ -741,9 +737,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
u = userActionsController.userActionsController(buff, users, "report") u = userActionsController.userActionsController(buff, users, "report")
@ -775,7 +771,7 @@ class Controller(object):
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events": if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
return return
else: else:
id = buffer.get_tweet()["id"] id = buffer.get_tweet().id
call_threaded(buffer.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id) call_threaded(buffer.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id)
def remove_from_favourites(self, *args, **kwargs): def remove_from_favourites(self, *args, **kwargs):
@ -783,7 +779,7 @@ class Controller(object):
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events": if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
return return
else: else:
id = buffer.get_tweet()["id"] id = buffer.get_tweet().id
call_threaded(buffer.session.api_call, call_name="destroy_favorite", id=id) call_threaded(buffer.session.api_call, call_name="destroy_favorite", id=id)
def toggle_like(self, *args, **kwargs): def toggle_like(self, *args, **kwargs):
@ -791,9 +787,9 @@ class Controller(object):
if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events": if buffer.type == "dm" or buffer.type == "people" or buffer.type == "events":
return return
else: else:
id = buffer.get_tweet()["id"] id = buffer.get_tweet().id
tweet = buffer.session.twitter.show_status(id=id, include_ext_alt_text=True, tweet_mode="extended") tweet = buffer.session.twitter.get_status(id=id, include_ext_alt_text=True, tweet_mode="extended")
if tweet["favorited"] == False: if tweet.favorited == False:
call_threaded(buffer.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id) call_threaded(buffer.session.api_call, call_name="create_favorite", _sound="favourite.ogg", id=id)
else: else:
call_threaded(buffer.session.api_call, call_name="destroy_favorite", id=id) call_threaded(buffer.session.api_call, call_name="destroy_favorite", id=id)
@ -808,7 +804,7 @@ class Controller(object):
elif buffer.type == "dm": elif buffer.type == "dm":
non_tweet = buffer.get_formatted_message() non_tweet = buffer.get_formatted_message()
item = buffer.get_right_tweet() item = buffer.get_right_tweet()
original_date = arrow.get(int(item["created_timestamp"][:-3])) original_date = arrow.get(int(item.created_timestamp))
date = original_date.shift(seconds=buffer.session.db["utc_offset"]).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage()) date = original_date.shift(seconds=buffer.session.db["utc_offset"]).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
msg = messages.viewTweet(non_tweet, [], False, date=date) msg = messages.viewTweet(non_tweet, [], False, date=date)
else: else:
@ -828,9 +824,9 @@ class Controller(object):
if not hasattr(buff, "get_right_tweet"): return if not hasattr(buff, "get_right_tweet"): return
tweet = buff.get_right_tweet() tweet = buff.get_right_tweet()
if buff.type == "people": if buff.type == "people":
users = [tweet["screen_name"]] users = [tweet.screen_name]
elif buff.type == "dm": elif buff.type == "dm":
users = [buff.session.get_user(tweet["message_create"]["sender_id"])["screen_name"]] users = [buff.session.get_user(tweet.message_create["sender_id"]).screen_name]
else: else:
users = utils.get_all_users(tweet, buff.session.db) users = utils.get_all_users(tweet, buff.session.db)
dlg = dialogs.userSelection.selectUserDialog(users=users, default=default) dlg = dialogs.userSelection.selectUserDialog(users=users, default=default)
@ -840,85 +836,85 @@ class Controller(object):
if usr == dlg.get_user(): if usr == dlg.get_user():
commonMessageDialogs.suspended_user() commonMessageDialogs.suspended_user()
return return
if usr["protected"] == True: if usr.protected == True:
if usr["following"] == False: if usr.following == False:
commonMessageDialogs.no_following() commonMessageDialogs.no_following()
return return
tl_type = dlg.get_action() tl_type = dlg.get_action()
if tl_type == "tweets": if tl_type == "tweets":
if usr["statuses_count"] == 0: if usr.statuses_count == 0:
commonMessageDialogs.no_tweets() commonMessageDialogs.no_tweets()
return return
if usr["id_str"] in buff.session.settings["other_buffers"]["timelines"]: if usr.id_str in buff.session.settings["other_buffers"]["timelines"]:
commonMessageDialogs.timeline_exist() commonMessageDialogs.timeline_exist()
return return
tl = twitterBuffers.baseBufferController(self.view.nb, "get_user_timeline", "%s-timeline" % (usr["id_str"],), buff.session, buff.session.db["user_name"], bufferType=None, sound="tweet_timeline.ogg", user_id=usr["id_str"], tweet_mode="extended") tl = twitterBuffers.baseBufferController(self.view.nb, "user_timeline", "%s-timeline" % (usr.id_str,), buff.session, buff.session.db["user_name"], bufferType=None, sound="tweet_timeline.ogg", user_id=usr.id_str, tweet_mode="extended")
try: try:
tl.start_stream(play_sound=False) tl.start_stream(play_sound=False)
except TwythonAuthError: except ValueError:
commonMessageDialogs.unauthorized() commonMessageDialogs.unauthorized()
return return
pos=self.view.search("timelines", buff.session.db["user_name"]) pos=self.view.search("timelines", buff.session.db["user_name"])
self.insert_buffer(tl, pos+1) self.insert_buffer(tl, pos+1)
self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(dlg.get_user()), pos=pos) self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}").format(dlg.get_user()), pos=pos)
buff.session.settings["other_buffers"]["timelines"].append(usr["id_str"]) buff.session.settings["other_buffers"]["timelines"].append(usr.id_str)
pub.sendMessage("buffer-title-changed", buffer=tl) pub.sendMessage("buffer-title-changed", buffer=tl)
buff.session.sound.play("create_timeline.ogg") buff.session.sound.play("create_timeline.ogg")
elif tl_type == "favourites": elif tl_type == "favourites":
if usr["favourites_count"] == 0: if usr.favourites_count == 0:
commonMessageDialogs.no_favs() commonMessageDialogs.no_favs()
return return
if usr["id_str"] in buff.session.settings["other_buffers"]["favourites_timelines"]: if usr.id_str in buff.session.settings["other_buffers"]["favourites_timelines"]:
commonMessageDialogs.timeline_exist() commonMessageDialogs.timeline_exist()
return return
tl = twitterBuffers.baseBufferController(self.view.nb, "get_favorites", "%s-favorite" % (usr["id_str"],), buff.session, buff.session.db["user_name"], bufferType=None, sound="favourites_timeline_updated.ogg", user_id=usr["id_str"], tweet_mode="extended") tl = twitterBuffers.baseBufferController(self.view.nb, "favorites", "%s-favorite" % (usr.id_str,), buff.session, buff.session.db["user_name"], bufferType=None, sound="favourites_timeline_updated.ogg", user_id=usr.id_str, tweet_mode="extended")
try: try:
tl.start_stream(play_sound=False) tl.start_stream(play_sound=False)
except TwythonAuthError: except ValueError:
commonMessageDialogs.unauthorized() commonMessageDialogs.unauthorized()
return return
pos=self.view.search("favs_timelines", buff.session.db["user_name"]) pos=self.view.search("favs_timelines", buff.session.db["user_name"])
self.insert_buffer(tl, pos+1) self.insert_buffer(tl, pos+1)
self.view.insert_buffer(buffer=tl.buffer, name=_(u"Likes for {}").format(dlg.get_user()), pos=pos) self.view.insert_buffer(buffer=tl.buffer, name=_(u"Likes for {}").format(dlg.get_user()), pos=pos)
buff.session.settings["other_buffers"]["favourites_timelines"].append(usr["id_str"]) buff.session.settings["other_buffers"]["favourites_timelines"].append(usr.id_str)
pub.sendMessage("buffer-title-changed", buffer=buff) pub.sendMessage("buffer-title-changed", buffer=buff)
buff.session.sound.play("create_timeline.ogg") buff.session.sound.play("create_timeline.ogg")
elif tl_type == "followers": elif tl_type == "followers":
if usr["followers_count"] == 0: if usr.followers_count == 0:
commonMessageDialogs.no_followers() commonMessageDialogs.no_followers()
return return
if usr["id_str"] in buff.session.settings["other_buffers"]["followers_timelines"]: if usr.id_str in buff.session.settings["other_buffers"]["followers_timelines"]:
commonMessageDialogs.timeline_exist() commonMessageDialogs.timeline_exist()
return return
tl = twitterBuffers.peopleBufferController(self.view.nb, "get_followers_list", "%s-followers" % (usr["id_str"],), buff.session, buff.session.db["user_name"], sound="new_event.ogg", user_id=usr["id_str"]) tl = twitterBuffers.peopleBufferController(self.view.nb, "followers", "%s-followers" % (usr.id_str,), buff.session, buff.session.db["user_name"], sound="new_event.ogg", user_id=usr.id_str)
try: try:
tl.start_stream(play_sound=False) tl.start_stream(play_sound=False)
except TwythonAuthError: except ValueError:
commonMessageDialogs.unauthorized() commonMessageDialogs.unauthorized()
return return
pos=self.view.search("followers_timelines", buff.session.db["user_name"]) pos=self.view.search("followers_timelines", buff.session.db["user_name"])
self.insert_buffer(tl, pos+1) self.insert_buffer(tl, pos+1)
self.view.insert_buffer(buffer=tl.buffer, name=_(u"Followers for {}").format(dlg.get_user()), pos=pos) self.view.insert_buffer(buffer=tl.buffer, name=_(u"Followers for {}").format(dlg.get_user()), pos=pos)
buff.session.settings["other_buffers"]["followers_timelines"].append(usr["id_str"]) buff.session.settings["other_buffers"]["followers_timelines"].append(usr.id_str)
buff.session.sound.play("create_timeline.ogg") buff.session.sound.play("create_timeline.ogg")
pub.sendMessage("buffer-title-changed", buffer=i) pub.sendMessage("buffer-title-changed", buffer=i)
elif tl_type == "friends": elif tl_type == "friends":
if usr["friends_count"] == 0: if usr.friends_count == 0:
commonMessageDialogs.no_friends() commonMessageDialogs.no_friends()
return return
if usr["id_str"] in buff.session.settings["other_buffers"]["friends_timelines"]: if usr.id_str in buff.session.settings["other_buffers"]["friends_timelines"]:
commonMessageDialogs.timeline_exist() commonMessageDialogs.timeline_exist()
return return
tl = twitterBuffers.peopleBufferController(self.view.nb, "get_friends_list", "%s-friends" % (usr["id_str"],), buff.session, buff.session.db["user_name"], sound="new_event.ogg", user_id=usr["id_str"]) tl = twitterBuffers.peopleBufferController(self.view.nb, "friends", "%s-friends" % (usr.id_str,), buff.session, buff.session.db["user_name"], sound="new_event.ogg", user_id=usr.id_str)
try: try:
tl.start_stream(play_sound=False) tl.start_stream(play_sound=False)
except TwythonAuthError: except ValueError:
commonMessageDialogs.unauthorized() commonMessageDialogs.unauthorized()
return return
pos=self.view.search("friends_timelines", buff.session.db["user_name"]) pos=self.view.search("friends_timelines", buff.session.db["user_name"])
self.insert_buffer(tl, pos+1) self.insert_buffer(tl, pos+1)
self.view.insert_buffer(buffer=tl.buffer, name=_(u"Friends for {}").format(dlg.get_user()), pos=pos) self.view.insert_buffer(buffer=tl.buffer, name=_(u"Friends for {}").format(dlg.get_user()), pos=pos)
buff.session.settings["other_buffers"]["friends_timelines"].append(usr["id_str"]) buff.session.settings["other_buffers"]["friends_timelines"].append(usr.id_str)
buff.session.sound.play("create_timeline.ogg") buff.session.sound.play("create_timeline.ogg")
pub.sendMessage("buffer-title-changed", buffer=i) pub.sendMessage("buffer-title-changed", buffer=i)
else: else:
@ -927,8 +923,8 @@ class Controller(object):
def open_conversation(self, *args, **kwargs): def open_conversation(self, *args, **kwargs):
buffer = self.get_current_buffer() buffer = self.get_current_buffer()
id = buffer.get_right_tweet()["id_str"] id = buffer.get_right_tweet().id_str
user = buffer.get_right_tweet()["user"]["screen_name"] user = buffer.get_right_tweet().user.screen_name
search = twitterBuffers.conversationBufferController(self.view.nb, "search", "%s-searchterm" % (id,), buffer.session, buffer.session.db["user_name"], bufferType="searchPanel", sound="search_updated.ogg", since_id=id, q="@{0}".format(user,)) search = twitterBuffers.conversationBufferController(self.view.nb, "search", "%s-searchterm" % (id,), buffer.session, buffer.session.db["user_name"], bufferType="searchPanel", sound="search_updated.ogg", since_id=id, q="@{0}".format(user,))
search.tweet = buffer.get_right_tweet() search.tweet = buffer.get_right_tweet()
search.start_stream(start=True) search.start_stream(start=True)
@ -968,9 +964,9 @@ class Controller(object):
def reverse_geocode(self, event=None): def reverse_geocode(self, event=None):
try: try:
tweet = self.get_current_buffer().get_tweet() tweet = self.get_current_buffer().get_tweet()
if tweet["coordinates"] != None: if tweet.coordinates != None:
x = tweet["coordinates"]["coordinates"][0] x = tweet.coordinates["coordinates"][0]
y = tweet["coordinates"]["coordinates"][1] y = tweet.coordinates["coordinates"][1]
address = geocoder.reverse_geocode(y, x, language = languageHandler.curLang) address = geocoder.reverse_geocode(y, x, language = languageHandler.curLang)
if event == None: output.speak(address[0].__str__()) if event == None: output.speak(address[0].__str__())
else: self.view.show_address(address[0].__str__()) else: self.view.show_address(address[0].__str__())
@ -988,9 +984,9 @@ class Controller(object):
def view_reverse_geocode(self, event=None): def view_reverse_geocode(self, event=None):
try: try:
tweet = self.get_current_buffer().get_right_tweet() tweet = self.get_current_buffer().get_right_tweet()
if tweet["coordinates"] != None: if tweet.coordinates != None:
x = tweet["coordinates"]["coordinates"][0] x = tweet.coordinates["coordinates"][0]
y = tweet["coordinates"]["coordinates"][1] y = tweet.coordinates["coordinates"][1]
address = geocoder.reverse_geocode(y, x, language = languageHandler.curLang) address = geocoder.reverse_geocode(y, x, language = languageHandler.curLang)
dlg = commonMessageDialogs.view_geodata(address[0].__str__()) dlg = commonMessageDialogs.view_geodata(address[0].__str__())
else: else:
@ -1330,7 +1326,7 @@ class Controller(object):
i.start_stream() i.start_stream()
else: else:
i.start_stream(play_sound=False) i.start_stream(play_sound=False)
except TwythonAuthError: except TweepError:
buff = self.view.search(i.name, i.account) buff = self.view.search(i.name, i.account)
i.remove_buffer(force=True) i.remove_buffer(force=True)
commonMessageDialogs.blocked_timeline() commonMessageDialogs.blocked_timeline()
@ -1354,34 +1350,34 @@ class Controller(object):
try: try:
if sessions.sessions[i].is_logged == False: continue if sessions.sessions[i].is_logged == False: continue
sessions.sessions[i].check_connection() sessions.sessions[i].check_connection()
except TwythonError: # We shouldn't allow this function to die. except TweepError: # We shouldn't allow this function to die.
pass pass
def create_new_buffer(self, buffer, account, create): def create_new_buffer(self, buffer, account, create):
buff = self.search_buffer("home_timeline", account) buff = self.search_buffer("home_timeline", account)
if create == True: if create == True:
if buffer == "favourites": if buffer == "favourites":
favourites = twitterBuffers.baseBufferController(self.view.nb, "get_favorites", "favourites", buff.session, buff.session.db["user_name"], tweet_mode="extended") favourites = twitterBuffers.baseBufferController(self.view.nb, "favorites", "favourites", buff.session, buff.session.db["user_name"], tweet_mode="extended")
self.buffers.append(favourites) self.buffers.append(favourites)
self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"])) self.view.insert_buffer(favourites.buffer, name=_(u"Likes"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"]))
favourites.start_stream(play_sound=False) favourites.start_stream(play_sound=False)
if buffer == "followers": if buffer == "followers":
followers = twitterBuffers.peopleBufferController(self.view.nb, "get_followers_list", "followers", buff.session, buff.session.db["user_name"], screen_name=buff.session.db["user_name"]) followers = twitterBuffers.peopleBufferController(self.view.nb, "followers", "followers", buff.session, buff.session.db["user_name"], screen_name=buff.session.db["user_name"])
self.buffers.append(followers) self.buffers.append(followers)
self.view.insert_buffer(followers.buffer, name=_(u"Followers"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"])) self.view.insert_buffer(followers.buffer, name=_(u"Followers"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"]))
followers.start_stream(play_sound=False) followers.start_stream(play_sound=False)
elif buffer == "friends": elif buffer == "friends":
friends = twitterBuffers.peopleBufferController(self.view.nb, "get_friends_list", "friends", buff.session, buff.session.db["user_name"], screen_name=buff.session.db["user_name"]) friends = twitterBuffers.peopleBufferController(self.view.nb, "friends", "friends", buff.session, buff.session.db["user_name"], screen_name=buff.session.db["user_name"])
self.buffers.append(friends) self.buffers.append(friends)
self.view.insert_buffer(friends.buffer, name=_(u"Friends"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"])) self.view.insert_buffer(friends.buffer, name=_(u"Friends"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"]))
friends.start_stream(play_sound=False) friends.start_stream(play_sound=False)
elif buffer == "blocked": elif buffer == "blocked":
blocks = twitterBuffers.peopleBufferController(self.view.nb, "list_blocks", "blocked", buff.session, buff.session.db["user_name"]) blocks = twitterBuffers.peopleBufferController(self.view.nb, "blocks", "blocked", buff.session, buff.session.db["user_name"])
self.buffers.append(blocks) self.buffers.append(blocks)
self.view.insert_buffer(blocks.buffer, name=_(u"Blocked users"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"])) self.view.insert_buffer(blocks.buffer, name=_(u"Blocked users"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"]))
blocks.start_stream(play_sound=False) blocks.start_stream(play_sound=False)
elif buffer == "muted": elif buffer == "muted":
muted = twitterBuffers.peopleBufferController(self.view.nb, "get_muted_users_list", "muted", buff.session, buff.session.db["user_name"]) muted = twitterBuffers.peopleBufferController(self.view.nb, "mutes", "muted", buff.session, buff.session.db["user_name"])
self.buffers.append(muted) self.buffers.append(muted)
self.view.insert_buffer(muted.buffer, name=_(u"Muted users"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"])) self.view.insert_buffer(muted.buffer, name=_(u"Muted users"), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"]))
muted.start_stream(play_sound=False) muted.start_stream(play_sound=False)
@ -1395,7 +1391,7 @@ class Controller(object):
if create in buff.session.settings["other_buffers"]["lists"]: if create in buff.session.settings["other_buffers"]["lists"]:
output.speak(_(u"This list is already opened"), True) output.speak(_(u"This list is already opened"), True)
return return
tl = twitterBuffers.listBufferController(self.view.nb, "get_list_statuses", create+"-list", buff.session, buff.session.db["user_name"], bufferType=None, list_id=utils.find_list(create, buff.session.db["lists"]), tweet_mode="extended") tl = twitterBuffers.listBufferController(self.view.nb, "list_timeline", create+"-list", buff.session, buff.session.db["user_name"], bufferType=None, list_id=utils.find_list(create, buff.session.db["lists"]), tweet_mode="extended")
buff.session.lists.append(tl) buff.session.lists.append(tl)
pos=self.view.search("lists", buff.session.db["user_name"]) pos=self.view.search("lists", buff.session.db["user_name"])
self.insert_buffer(tl, pos) self.insert_buffer(tl, pos)
@ -1536,7 +1532,7 @@ class Controller(object):
if i.session != None and i.session.is_logged == True: if i.session != None and i.session.is_logged == True:
try: try:
i.start_stream(mandatory=True) i.start_stream(mandatory=True)
except TwythonAuthError: except TweepError:
buff = self.view.search(i.name, i.account) buff = self.view.search(i.name, i.account)
i.remove_buffer(force=True) i.remove_buffer(force=True)
commonMessageDialogs.blocked_timeline() commonMessageDialogs.blocked_timeline()

View File

@ -216,52 +216,52 @@ class viewTweet(basicTweet):
text = "" text = ""
for i in range(0, len(tweetList)): for i in range(0, len(tweetList)):
# tweets with message keys are longer tweets, the message value is the full messaje taken from twishort. # tweets with message keys are longer tweets, the message value is the full messaje taken from twishort.
if "message" in tweetList[i] and tweetList[i]["is_quote_status"] == False: if hasattr(tweetList[i], "message") and tweetList[i].is_quote_status == False:
value = "message" value = "message"
else: else:
value = "full_text" value = "full_text"
if "retweeted_status" in tweetList[i] and tweetList[i]["is_quote_status"] == False: if hasattr(tweetList[i], "retweeted_status") and tweetList[i].is_quote_status == False:
if ("message" in tweetList[i]) == False: if not hasattr(tweetList[i], "message"):
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["full_text"]) text = text + "rt @%s: %s\n" % (tweetList[i].retweeted_status.user.screen_name, tweetList[i].retweeted_status.full_text)
else: else:
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value]) text = text + "rt @%s: %s\n" % (tweetList[i].retweeted_status.user.screen_name, getattr(tweetList[i], value))
else: else:
text = text + " @%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value]) text = text + " @%s: %s\n" % (tweetList[i].user.screen_name, getattr(tweetList[i], value))
# tweets with extended_entities could include image descriptions. # tweets with extended_entities could include image descriptions.
if "extended_entities" in tweetList[i] and "media" in tweetList[i]["extended_entities"]: if getattr(tweetList[i], "extended_entities") and "media" in tweetList[i].extended_entities:
for z in tweetList[i]["extended_entities"]["media"]: for z in tweetList[i].extended_entities["media"]:
if "ext_alt_text" in z and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
if "retweeted_status" in tweetList[i] and "extended_entities" in tweetList[i]["retweeted_status"] and "media" in tweetList[i]["retweeted_status"]["extended_entities"]: if hasattr(tweetList[i], "retweeted_status") and hasattr(tweetList[i].retweeted_status, "extended_entities") and "media" in tweetList[i].retweeted_status["extended_entities"]:
for z in tweetList[i]["retweeted_status"]["extended_entities"]["media"]: for z in tweetList[i].retweeted_status.extended_entities["media"]:
if "ext_alt_text" in z and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
# set rt and likes counters. # set rt and likes counters.
rt_count = str(tweet["retweet_count"]) rt_count = str(tweet.retweet_count)
favs_count = str(tweet["favorite_count"]) favs_count = str(tweet.favorite_count)
# Gets the client from where this tweet was made. # Gets the client from where this tweet was made.
source = re.sub(r"(?s)<.*?>", "", tweet["source"]) source = tweet.source
original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en") original_date = arrow.get(tweet.created_at, locale="en")
date = original_date.shift(seconds=utc_offset).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage()) date = original_date.shift(seconds=utc_offset).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage())
if text == "": if text == "":
if "message" in tweet: if hasattr(tweet, "message"):
value = "message" value = "message"
else: else:
value = "full_text" value = "full_text"
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
if ("message" in tweet) == False: if not hasattr(tweet, "message"):
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet["retweeted_status"]["full_text"]) text = "rt @%s: %s" % (tweet.retweeted_status.user.screen_name, tweet.retweeted_status.full_text)
else: else:
text = "rt @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], tweet[value]) text = "rt @%s: %s" % (tweet.retweeted_status.user.screen_name, getattr(tweet, value))
else: else:
text = tweet[value] text = getattr(tweet, value)
text = self.clear_text(text) text = self.clear_text(text)
if "extended_entities" in tweet and "media" in tweet["extended_entities"]: if hasattr(tweet, "extended_entities") and "media" in tweet.extended_entities:
for z in tweet["extended_entities"]["media"]: for z in tweet.extended_entities["media"]:
if "ext_alt_text" in z and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
if "retweeted_status" in tweet and "extended_entities" in tweet["retweeted_status"] and "media" in tweet["retweeted_status"]["extended_entities"]: if hasattr(tweet, "retweeted_status") and hasattr(tweet.retweeted_status, "extended_entities") and "media" in tweet.retweeted_status.extended_entities:
for z in tweet["retweeted_status"]["extended_entities"]["media"]: for z in tweet.retweeted_status.extended_entities["media"]:
if "ext_alt_text" in z and z["ext_alt_text"] != None: if "ext_alt_text" in z and z["ext_alt_text"] != None:
image_description.append(z["ext_alt_text"]) image_description.append(z["ext_alt_text"])
self.message = message.viewTweet(text, rt_count, favs_count, source, date) self.message = message.viewTweet(text, rt_count, favs_count, source, date)

View File

@ -1,6 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from builtins import object
from wxUI.dialogs import trends from wxUI.dialogs import trends
import widgetUtils import widgetUtils
@ -10,7 +8,7 @@ class trendingTopicsController(object):
self.countries = {} self.countries = {}
self.cities = {} self.cities = {}
self.dialog = trends.trendingTopicsDialog() self.dialog = trends.trendingTopicsDialog()
self.information = session.twitter.get_available_trends() self.information = session.twitter.trends_available()
self.split_information() self.split_information()
widgetUtils.connect_event(self.dialog.country, widgetUtils.RADIOBUTTON, self.get_places) widgetUtils.connect_event(self.dialog.country, widgetUtils.RADIOBUTTON, self.get_places)
widgetUtils.connect_event(self.dialog.city, widgetUtils.RADIOBUTTON, self.get_places) widgetUtils.connect_event(self.dialog.city, widgetUtils.RADIOBUTTON, self.get_places)

View File

@ -6,7 +6,7 @@ import output
from wxUI.dialogs import update_profile, show_user from wxUI.dialogs import update_profile, show_user
import logging import logging
log = logging.getLogger("controller.user") log = logging.getLogger("controller.user")
from twython import TwythonError from tweepy.error import TweepError
from sessions.twitter import utils from sessions.twitter import utils
class profileController(object): class profileController(object):
@ -24,36 +24,36 @@ class profileController(object):
else: else:
try: try:
self.get_data(screen_name=self.user) self.get_data(screen_name=self.user)
except TwythonError as err: except TweepError as err:
if err.error_code == 404: if err.api_code == 50:
wx.MessageDialog(None, _(u"That user does not exist"), _(u"Error"), wx.ICON_ERROR).ShowModal() wx.MessageDialog(None, _(u"That user does not exist"), _(u"Error"), wx.ICON_ERROR).ShowModal()
if err.error_code == 403: if err.api_code == 403:
wx.MessageDialog(None, _(u"User has been suspended"), _(u"Error"), wx.ICON_ERROR).ShowModal() wx.MessageDialog(None, _(u"User has been suspended"), _(u"Error"), wx.ICON_ERROR).ShowModal()
log.error("error %d: %s" % (err.error_code, err.msg)) log.error("error %d: %s" % (err.api_code, err.reason))
return return
self.dialog = show_user.showUserProfile() self.dialog = show_user.showUserProfile()
string = self.get_user_info() string = self.get_user_info()
self.dialog.set("text", string) self.dialog.set("text", string)
self.dialog.set_title(_(u"Information for %s") % (self.data["screen_name"])) self.dialog.set_title(_(u"Information for %s") % (self.data.screen_name))
if self.data["url"] != None: if self.data.url != None:
self.dialog.enable_url() self.dialog.enable_url()
widgetUtils.connect_event(self.dialog.url, widgetUtils.BUTTON_PRESSED, self.visit_url) widgetUtils.connect_event(self.dialog.url, widgetUtils.BUTTON_PRESSED, self.visit_url)
if self.dialog.get_response() == widgetUtils.OK and self.user == None: if self.dialog.get_response() == widgetUtils.OK and self.user == None:
self.do_update() self.do_update()
def get_data(self, screen_name): def get_data(self, screen_name):
self.data = self.session.twitter.show_user(screen_name=screen_name) self.data = self.session.twitter.get_user(screen_name=screen_name)
if screen_name != self.session.db["user_name"]: if screen_name != self.session.db["user_name"]:
self.friendship_status = self.session.twitter.show_friendship(source_screen_name=self.session.db["user_name"], target_screen_name=screen_name) self.friendship_status = self.session.twitter.show_friendship(source_screen_name=self.session.db["user_name"], target_screen_name=screen_name)
def fill_profile_fields(self): def fill_profile_fields(self):
self.dialog.set_name(self.data["name"]) self.dialog.set_name(self.data.name)
if self.data["url"] != None: if self.data.url != None:
self.dialog.set_url(self.data["url"]) self.dialog.set_url(self.data.url)
if len(self.data["location"]) > 0: if len(self.data.location) > 0:
self.dialog.set_location(self.data["location"]) self.dialog.set_location(self.data.location)
if len(self.data["description"]) > 0: if len(self.data.description) > 0:
self.dialog.set_description(self.data["description"]) self.dialog.set_description(self.data.description)
def get_image(self): def get_image(self):
file = self.dialog.upload_picture() file = self.dialog.upload_picture()
@ -83,46 +83,46 @@ class profileController(object):
if self.file != None: if self.file != None:
try: try:
self.session.twitter.update_profile_image(image=self.file) self.session.twitter.update_profile_image(image=self.file)
except TwythonError as e: except TweepError as e:
output.speak(u"Error %s. %s" % (e.error_code, e.msg)) output.speak(u"Error %s. %s" % (e.api_code, e.reason))
try: try:
self.session.twitter.update_profile(name=name, description=description, location=location, url=url) self.session.twitter.update_profile(name=name, description=description, location=location, url=url)
except TwythonError as e: except TweepError as e:
output.speak(u"Error %s. %s" % (e.error_code, e.msg)) output.speak(u"Error %s. %s" % (e.api_code, e.reason))
def get_user_info(self): def get_user_info(self):
string = u"" string = u""
string = string + _(u"Username: @%s\n") % (self.data["screen_name"]) string = string + _(u"Username: @%s\n") % (self.data.screen_name)
string = string + _(u"Name: %s\n") % (self.data["name"]) string = string + _(u"Name: %s\n") % (self.data.name)
if self.data["location"] != "": if self.data.location != "":
string = string + _(u"Location: %s\n") % (self.data["location"]) string = string + _(u"Location: %s\n") % (self.data.location)
if self.data["url"] != None: if self.data.url != None:
string = string+ _(u"URL: %s\n") % (self.data["entities"]["url"]["urls"][0]["expanded_url"]) string = string+ _(u"URL: %s\n") % (self.data.entities["url"]["urls"][0]["expanded_url"])
if self.data["description"] != "": if self.data.description != "":
if self.data["entities"].get("description") != None and self.data["entities"]["description"].get("urls"): if self.data.entities.get("description") != None and self.data.entities["description"].get("urls"):
self.data["description"] = utils.expand_urls(self.data["description"], self.data["entities"]["description"]) self.data.description = utils.expand_urls(self.data.description, self.data.entities["description"])
string = string+ _(u"Bio: %s\n") % (self.data["description"]) string = string+ _(u"Bio: %s\n") % (self.data.description)
if self.data["protected"] == True: protected = _(u"Yes") if self.data.protected == True: protected = _(u"Yes")
else: protected = _(u"No") else: protected = _(u"No")
string = string+ _(u"Protected: %s\n") % (protected) string = string+ _(u"Protected: %s\n") % (protected)
if hasattr(self, "friendship_status"): if hasattr(self, "friendship_status"):
relation = False relation = False
friendship = "Relationship: " friendship = "Relationship: "
if self.friendship_status["relationship"]["target"]["followed_by"]: if self.friendship_status[0].following:
friendship += _(u"You follow {0}. ").format(self.data["name"],) friendship += _(u"You follow {0}. ").format(self.data.name,)
relation = True relation = True
if self.friendship_status["relationship"]["target"]["following"]: if self.friendship_status[1].following:
friendship += _(u"{0} is following you.").format(self.data["name"],) friendship += _(u"{0} is following you.").format(self.data.name,)
relation = True relation = True
if relation == True: if relation == True:
string = string+friendship+"\n" string = string+friendship+"\n"
string = string+_(u"Followers: %s\n Friends: %s\n") % (self.data["followers_count"], self.data["friends_count"]) string = string+_(u"Followers: %s\n Friends: %s\n") % (self.data.followers_count, self.data.friends_count)
if self.data["verified"] == True: verified = _(u"Yes") if self.data.verified == True: verified = _(u"Yes")
else: verified = _(u"No") else: verified = _(u"No")
string = string+ _(u"Verified: %s\n") % (verified) string = string+ _(u"Verified: %s\n") % (verified)
string = string+ _(u"Tweets: %s\n") % (self.data["statuses_count"]) string = string+ _(u"Tweets: %s\n") % (self.data.statuses_count)
string = string+ _(u"Likes: %s") % (self.data["favourites_count"]) string = string+ _(u"Likes: %s") % (self.data.favourites_count)
return string return string
def visit_url(self, *args, **kwargs): def visit_url(self, *args, **kwargs):
webbrowser.open_new_tab(self.data["url"]) webbrowser.open_new_tab(self.data.url)

View File

@ -1,12 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from builtins import object
import re
import widgetUtils import widgetUtils
import output import output
from wxUI.dialogs import userActions from wxUI.dialogs import userActions
from pubsub import pub from pubsub import pub
from twython import TwythonError from tweepy.error import TweepError
from extra import autocompletionUsers from extra import autocompletionUsers
class userActionsController(object): class userActionsController(object):
@ -32,51 +29,51 @@ class userActionsController(object):
def follow(self, user): def follow(self, user):
try: try:
self.session.twitter.create_friendship(screen_name=user ) self.session.twitter.create_friendship(screen_name=user )
except TwythonError as err: except TweepError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True) output.speak("Error %s: %s" % (err.api_code, err.reason), True)
def unfollow(self, user): def unfollow(self, user):
try: try:
id = self.session.twitter.destroy_friendship(screen_name=user ) id = self.session.twitter.destroy_friendship(screen_name=user )
except TwythonError as err: except TweepError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True) output.speak("Error %s: %s" % (err.api_code, err.reason), True)
def mute(self, user): def mute(self, user):
try: try:
id = self.session.twitter.create_mute(screen_name=user ) id = self.session.twitter.create_mute(screen_name=user )
except TwythonError as err: except TweepError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True) output.speak("Error %s: %s" % (err.api_code, err.reason), True)
def unmute(self, user): def unmute(self, user):
try: try:
id = self.session.twitter.destroy_mute(screen_name=user ) id = self.session.twitter.destroy_mute(screen_name=user )
except TwythonError as err: except TweepError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True) output.speak("Error %s: %s" % (err.api_code, err.reason), True)
def report(self, user): def report(self, user):
try: try:
id = self.session.twitter.report_spam(screen_name=user ) id = self.session.twitter.report_spam(screen_name=user )
except TwythonError as err: except TweepError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True) output.speak("Error %s: %s" % (err.api_code, err.reason), True)
def block(self, user): def block(self, user):
try: try:
id = self.session.twitter.create_block(screen_name=user ) id = self.session.twitter.create_block(screen_name=user )
except TwythonError as err: except TweepError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True) output.speak("Error %s: %s" % (err.api_code, err.reason), True)
def unblock(self, user): def unblock(self, user):
try: try:
id = self.session.twitter.destroy_block(screen_name=user ) id = self.session.twitter.destroy_block(screen_name=user )
except TwythonError as err: except TweepError as err:
output.speak("Error %s: %s" % (err.error_code, err.msg), True) output.speak("Error %s: %s" % (err.api_code, err.reason), True)
def ignore_client(self, user): def ignore_client(self, user):
tweet = self.buffer.get_right_tweet() tweet = self.buffer.get_right_tweet()
if "sender" in tweet: if hasattr(tweet, "sender"):
output.speak(_(u"You can't ignore direct messages")) output.speak(_(u"You can't ignore direct messages"))
return return
client = re.sub(r"(?s)<.*?>", "", tweet["source"]) client = tweet.source
if client not in self.session.settings["twitter"]["ignored_clients"]: if client not in self.session.settings["twitter"]["ignored_clients"]:
self.session.settings["twitter"]["ignored_clients"].append(client) self.session.settings["twitter"]["ignored_clients"].append(client)
self.session.settings.write() self.session.settings.write()

View File

@ -20,7 +20,6 @@ import config
from .long_tweets import twishort, tweets from .long_tweets import twishort, tweets
log = logging.getLogger("compose") log = logging.getLogger("compose")
def StripChars(s): def StripChars(s):
"""Converts any html entities in s to their unicode-decoded equivalents and returns a string.""" """Converts any html entities in s to their unicode-decoded equivalents and returns a string."""
entity_re = re.compile(r"&(#\d+|\w+);") entity_re = re.compile(r"&(#\d+|\w+);")
@ -39,41 +38,41 @@ chars = "abcdefghijklmnopqrstuvwxyz"
def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=None): def compose_tweet(tweet, db, relative_times, show_screen_names=False, session=None):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is.""" """ It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
if system == "Windows": if system == "Windows":
original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en") original_date = arrow.get(tweet.created_at, locale="en")
if relative_times == True: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else: else:
ts = tweet["created_at"] ts = tweet.created_at
if "message" in tweet: if hasattr(tweet, "message"):
value = "message" value = "message"
elif "full_text" in tweet: elif hasattr(tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
if "retweeted_status" in tweet and value != "message": if hasattr(tweet, "retweeted_status") and value != "message":
text = StripChars(tweet["retweeted_status"][value]) text = StripChars(getattr(tweet.retweeted_status, value))
else: else:
text = StripChars(tweet[value]) text = StripChars(getattr(tweet, value))
if show_screen_names: if show_screen_names:
user = tweet["user"]["screen_name"] user = tweet.user.screen_name
else: else:
user = tweet["user"]["name"] user = tweet.user.name
source = re.sub(r"(?s)<.*?>", "", tweet["source"]) source = re.sub(r"(?s)<.*?>", "", tweet.source)
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
if ("message" in tweet) == False and tweet["retweeted_status"]["is_quote_status"] == False: if (hasattr(tweet, "message")) == False and tweet.retweeted_status.is_quote_status == False:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text) text = "RT @%s: %s" % (tweet.retweeted_status.user.screen_name, text)
elif tweet["retweeted_status"]["is_quote_status"]: elif tweet.retweeted_status.is_quote_status:
text = "%s" % (text) text = "%s" % (text)
else: else:
text = "RT @%s: %s" % (tweet["retweeted_status"]["user"]["screen_name"], text) text = "RT @%s: %s" % (tweet.retweeted_status.user.screen_name, text)
if ("message" in tweet) == False: if not hasattr(tweet, "message"):
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
text = utils.expand_urls(text, tweet["retweeted_status"]["entities"]) text = utils.expand_urls(text, tweet.retweeted_status.entities)
else: else:
text = utils.expand_urls(text, tweet["entities"]) text = utils.expand_urls(text, tweet.entities)
if config.app['app-settings']['handle_longtweets']: pass if config.app['app-settings']['handle_longtweets']: pass
return [user+", ", text, ts+", ", source] return [user+", ", text, ts+", ", source]
@ -83,76 +82,76 @@ def compose_direct_message(item, db, relative_times, show_screen_names=False, se
if system == "Windows": if system == "Windows":
# Let's remove the last 3 digits in the timestamp string. # Let's remove the last 3 digits in the timestamp string.
# Twitter sends their "epoch" timestamp with 3 digits for milliseconds and arrow doesn't like it. # Twitter sends their "epoch" timestamp with 3 digits for milliseconds and arrow doesn't like it.
original_date = arrow.get(int(item["created_timestamp"][:-3])) original_date = arrow.get(int(item.created_timestamp))
if relative_times == True: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else: else:
ts = item["created_timestamp"] ts = item.created_timestamp
text = StripChars(item["message_create"]["message_data"]["text"]) text = StripChars(item.message_create["message_data"]["text"])
source = "DM" source = "DM"
sender = session.get_user(item["message_create"]["sender_id"]) sender = session.get_user(item.message_create["sender_id"])
if db["user_name"] == sender["screen_name"]: if db["user_name"] == sender.screen_name:
if show_screen_names: if show_screen_names:
user = _(u"Dm to %s ") % (session.get_user(item["message_create"]["target"]["recipient_id"])["screen_name"]) user = _(u"Dm to %s ") % (session.get_user(item.message_create["target"]["recipient_id"]).screen_name)
else: else:
user = _(u"Dm to %s ") % (session.get_user(item["message_create"]["target"]["recipient_id"])["name"]) user = _(u"Dm to %s ") % (session.get_user(item.message_create["target"]["recipient_id"]).name)
else: else:
if show_screen_names: if show_screen_names:
user = sender["screen_name"] user = sender.screen_name
else: else:
user = sender["name"] user = sender.name
if text[-1] in chars: text=text+"." if text[-1] in chars: text=text+"."
text = utils.expand_urls(text, item["message_create"]["message_data"]["entities"]) text = utils.expand_urls(text, item.message_create["message_data"]["entities"])
return [user+", ", text, ts+", ", source] return [user+", ", text, ts+", ", source]
def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False, session=None): def compose_quoted_tweet(quoted_tweet, original_tweet, show_screen_names=False, session=None):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is.""" """ It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
if "retweeted_status" in quoted_tweet: if hasattr(quoted_tweet, "retweeted_status"):
if "full_text" in quoted_tweet["retweeted_status"]: if hasattr(quoted_tweet.retweeted_status, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
text = StripChars(quoted_tweet["retweeted_status"][value]) text = StripChars(getattr(quoted_tweet.retweeted_status, value))
else: else:
if "full_text" in quoted_tweet: if hasattr(quoted_tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
text = StripChars(quoted_tweet[value]) text = StripChars(getattr(quoted_tweet, value))
if show_screen_names: if show_screen_names:
quoting_user = quoted_tweet["user"]["screen_name"] quoting_user = quoted_tweet.user.screen_name
else: else:
quoting_user = quoted_tweet["user"]["name"] quoting_user = quoted_tweet.user.name
source = re.sub(r"(?s)<.*?>", "", quoted_tweet["source"]) source = quoted_tweet.source
if "retweeted_status" in quoted_tweet: if hasattr(quoted_tweet, "retweeted_status"):
text = "rt @%s: %s" % (quoted_tweet["retweeted_status"]["user"]["screen_name"], text) text = "rt @%s: %s" % (quoted_tweet.retweeted_status.user.screen_name, text)
if text[-1] in chars: text=text+"." if text[-1] in chars: text=text+"."
original_user = original_tweet["user"]["screen_name"] original_user = original_tweet.user.screen_name
if "message" in original_tweet: if hasattr(original_tweet, "message"):
original_text = original_tweet["message"] original_text = original_tweet.message
elif "full_text" in original_tweet: elif hasattr(original_tweet, "full_text"):
original_text = StripChars(original_tweet["full_text"]) original_text = StripChars(original_tweet.full_text)
else: else:
original_text = StripChars(original_tweet["text"]) original_text = StripChars(original_tweet.text)
quoted_tweet["message"] = _(u"{0}. Quoted tweet from @{1}: {2}").format( text, original_user, original_text) quoted_tweet.message = _(u"{0}. Quoted tweet from @{1}: {2}").format( text, original_user, original_text)
quoted_tweet = tweets.clear_url(quoted_tweet) quoted_tweet = tweets.clear_url(quoted_tweet)
quoted_tweet["entities"]["urls"].extend(original_tweet["entities"]["urls"]) quoted_tweet.entities["urls"].extend(original_tweet.entities["urls"])
return quoted_tweet return quoted_tweet
def compose_followers_list(tweet, db, relative_times=True, show_screen_names=False, session=None): def compose_followers_list(tweet, db, relative_times=True, show_screen_names=False, session=None):
if system == "Windows": if system == "Windows":
original_date = arrow.get(tweet["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en") original_date = arrow.get(tweet.created_at, locale="en")
if relative_times == True: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.curLang[:2]) ts = original_date.humanize(locale=languageHandler.curLang[:2])
else: else:
ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) ts = original_date.shift(seconds=db["utc_offset"]).format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
else: else:
ts = tweet["created_at"] ts = tweet.created_at
if "status" in tweet: if hasattr(tweet, "status"):
if len(tweet["status"]) > 4 and system == "Windows": if system == "Windows":
original_date2 = arrow.get(tweet["status"]["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en") original_date2 = arrow.get(tweet.status.created_at, locale="en")
if relative_times: if relative_times:
ts2 = original_date2.humanize(locale=languageHandler.curLang[:2]) ts2 = original_date2.humanize(locale=languageHandler.curLang[:2])
else: else:
@ -161,14 +160,14 @@ def compose_followers_list(tweet, db, relative_times=True, show_screen_names=Fal
ts2 = _("Unavailable") ts2 = _("Unavailable")
else: else:
ts2 = _("Unavailable") ts2 = _("Unavailable")
return [_(u"%s (@%s). %s followers, %s friends, %s tweets. Last tweeted %s. Joined Twitter %s") % (tweet["name"], tweet["screen_name"], tweet["followers_count"], tweet["friends_count"], tweet["statuses_count"], ts2, ts)] return [_(u"%s (@%s). %s followers, %s friends, %s tweets. Last tweeted %s. Joined Twitter %s") % (tweet.name, tweet.screen_name, tweet.followers_count, tweet.friends_count, tweet.statuses_count, ts2, ts)]
def compose_list(list): def compose_list(list):
name = list["name"] name = list.name
if list["description"] == None: description = _(u"No description available") if list.description == None: description = _(u"No description available")
else: description = list["description"] else: description = list.description
user = list["user"]["name"] user = list.user.name
members = str(list["member_count"]) members = str(list.member_count)
if list["mode"] == "private": status = _(u"private") if list.mode == "private": status = _(u"private")
else: status = _(u"public") else: status = _(u"public")
return [name, description, user, members, status] return [name, description, user, members, status]

View File

@ -23,30 +23,30 @@ def is_long(tweet):
""" Check if the passed tweet contains a quote in its metadata. """ Check if the passed tweet contains a quote in its metadata.
tweet dict: a tweet dictionary. tweet dict: a tweet dictionary.
returns True if a quote is detected, False otherwise.""" returns True if a quote is detected, False otherwise."""
if "quoted_status_id" in tweet and "quoted_status" in tweet: if hasattr(tweet, "quoted_status_id") and hasattr(tweet, "quoted_status"):
return tweet["quoted_status_id"] return tweet.quoted_status_id
elif "retweeted_status" in tweet and "quoted_status_id" in tweet["retweeted_status"] and "quoted_status" in tweet["retweeted_status"]: elif hasattr(tweet, "retweeted_status") and hasattr(tweet, "quoted_status_id") and hasattr(tweet, "quoted_status"):
return tweet["retweeted_status"]["quoted_status_id"] return tweet.retweeted_status.quoted_status_id
return False return False
def clear_url(tweet): def clear_url(tweet):
""" Reads data from a quoted tweet and removes the link to the Status from the tweet's text. """ Reads data from a quoted tweet and removes the link to the Status from the tweet's text.
tweet dict: a tweet dictionary. tweet dict: a tweet dictionary.
returns a tweet dictionary without the URL to the status ID in its text to display.""" returns a tweet dictionary without the URL to the status ID in its text to display."""
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
if "full_text" in tweet["retweeted_status"]: if hasattr(tweet.retweeted_status, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
urls = utils.find_urls_in_text(tweet["retweeted_status"][value]) urls = utils.find_urls_in_text(getattr(tweet.retweeted_status, value))
try: tweet["message"] = tweet["message"].replace(urls[-1], "") try: tweet.message = tweet.message.replace(urls[-1], "")
except IndexError: pass except IndexError: pass
else: else:
if "full_text" in tweet: if hasattr(tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
urls = utils.find_urls_in_text(tweet[value]) urls = utils.find_urls_in_text(getattr(tweet, value))
try: tweet["message"] = tweet["message"].replace(urls[-1], "") try: tweet.message = tweet.message.replace(urls[-1], "")
except IndexError: pass except IndexError: pass
return tweet return tweet

View File

@ -40,21 +40,21 @@ def is_long(tweet):
""" Check if the passed tweet is made with Twishort. """ Check if the passed tweet is made with Twishort.
returns True if is a long tweet, False otherwise.""" returns True if is a long tweet, False otherwise."""
long = False long = False
for url in range(0, len(tweet["entities"]["urls"])): for url in range(0, len(tweet.entities["urls"])):
try: try:
if tweet["entities"]["urls"][url] != None and "twishort.com" in tweet["entities"]["urls"][url]["expanded_url"]: if tweet.entities["urls"][url] != None and "twishort.com" in tweet.entities["urls"][url]["expanded_url"]:
long = get_twishort_uri(tweet["entities"]["urls"][url]["expanded_url"]) long = get_twishort_uri(tweet.entities["urls"][url]["expanded_url"])
except IndexError: except IndexError:
pass pass
# sometimes Twitter returns URL's with None objects, so let's take it. # sometimes Twitter returns URL's with None objects, so let's take it.
# see https://github.com/manuelcortez/TWBlue/issues/103 # see https://github.com/manuelcortez/TWBlue/issues/103
except TypeError: except TypeError:
pass pass
if long == False and "retweeted_status" in tweet: if long == False and hasattr(tweet, "retweeted_status"):
for url in range(0, len(tweet["retweeted_status"]["entities"]["urls"])): for url in range(0, len(tweet.retweeted_status.entities["urls"])):
try: try:
if tweet["retweeted_status"]["entities"]["urls"][url] != None and "twishort.com" in tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]: if tweet.retweeted_status.entities["urls"][url] != None and "twishort.com" in tweet.retweeted_status.entities["urls"][url]["expanded_url"]:
long = get_twishort_uri(tweet["retweeted_status"]["entities"]["urls"][url]["expanded_url"]) long = get_twishort_uri(tweet.retweeted_status.entities["urls"][url]["expanded_url"])
except IndexError: except IndexError:
pass pass
except TypeError: except TypeError:

View File

@ -1,8 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" This is the main session needed to access all Twitter Features.""" """ This is the main session needed to access all Twitter Features."""
from __future__ import absolute_import
from __future__ import unicode_literals
from builtins import range
import os import os
import time import time
import logging import logging
@ -12,7 +9,8 @@ import config
import output import output
import application import application
from pubsub import pub from pubsub import pub
from twython import Twython, TwythonError, TwythonRateLimitError, TwythonAuthError import tweepy
from tweepy.error import TweepError
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
from keys import keyring from keys import keyring
from sessions import base from sessions import base
@ -31,6 +29,8 @@ class Session(base.baseSession):
data list: A list with tweets. data list: A list with tweets.
ignore_older bool: if set to True, items older than the first element on the list will be ignored. ignore_older bool: if set to True, items older than the first element on the list will be ignored.
returns the number of items that have been added in this execution""" returns the number of items that have been added in this execution"""
if name == "direct_messages":
return self.order_direct_messages(data)
num = 0 num = 0
last_id = None last_id = None
if (name in self.db) == False: if (name in self.db) == False:
@ -39,43 +39,38 @@ class Session(base.baseSession):
self.db["users"] = {} self.db["users"] = {}
if ignore_older and len(self.db[name]) > 0: if ignore_older and len(self.db[name]) > 0:
if self.settings["general"]["reverse_timelines"] == False: if self.settings["general"]["reverse_timelines"] == False:
last_id = self.db[name][0]["id"] last_id = self.db[name][0].id
else: else:
last_id = self.db[name][-1]["id"] last_id = self.db[name][-1].id
for i in data: for i in data:
if ignore_older and last_id != None: if ignore_older and last_id != None:
if i["id"] < last_id: if i.id < last_id:
log.error("Ignoring an older tweet... Last id: {0}, tweet id: {1}".format(last_id, i["id"])) log.error("Ignoring an older tweet... Last id: {0}, tweet id: {1}".format(last_id, i.id))
continue continue
if utils.find_item(i["id"], self.db[name]) == None and utils.is_allowed(i, self.settings, name) == True: if utils.find_item(i.id, self.db[name]) == None and utils.is_allowed(i, self.settings, name) == True:
i = self.check_quoted_status(i) i = self.check_quoted_status(i)
i = self.check_long_tweet(i) i = self.check_long_tweet(i)
if i == False: continue if i == False: continue
if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i)
else: self.db[name].insert(0, i) else: self.db[name].insert(0, i)
num = num+1 num = num+1
if ("user" in i) == True: if hasattr(i, "user"):
if (i["user"]["id"] in self.db["users"]) == False: if (i.user.id in self.db["users"]) == False:
self.db["users"][i["user"]["id"]] = i["user"] self.db["users"][i.user.id] = i.user
return num return num
def order_cursored_buffer(self, name, data): def order_people(self, name, data):
""" Put new items on the local database. Useful for cursored buffers (followers, friends, users of a list and searches) """ Put new items on the local database. Useful for cursored buffers (followers, friends, users of a list and searches)
name str: The name for the buffer stored in the dictionary. name str: The name for the buffer stored in the dictionary.
data list: A list with items and some information about cursors. data list: A list with items and some information about cursors.
returns the number of items that have been added in this execution""" returns the number of items that have been added in this execution"""
# Direct messages should be added to db in other function.
# Because they will be populating two buffers with one endpoint.
if name == "direct_messages":
return self.order_direct_messages(data)
num = 0 num = 0
if (name in self.db) == False: if (name in self.db) == False:
self.db[name] = {} self.db[name] = []
self.db[name]["items"] = []
for i in data: for i in data:
if utils.find_item(i["id"], self.db[name]["items"]) == None: if utils.find_item(i.id, self.db[name]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db[name]["items"].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db[name].append(i)
else: self.db[name]["items"].insert(0, i) else: self.db[name].insert(0, i)
num = num+1 num = num+1
return num return num
@ -86,24 +81,27 @@ class Session(base.baseSession):
incoming = 0 incoming = 0
sent = 0 sent = 0
if ("direct_messages" in self.db) == False: if ("direct_messages" in self.db) == False:
self.db["direct_messages"] = {} self.db["direct_messages"] = []
self.db["direct_messages"]["items"] = []
for i in data: for i in data:
if i["message_create"]["sender_id"] == self.db["user_id"]: # Twitter returns sender_id as str, which must be converted to int in order to match to our user_id object.
if "sent_direct_messages" in self.db and utils.find_item(i["id"], self.db["sent_direct_messages"]["items"]) == None: if int(i.message_create["sender_id"]) == self.db["user_id"]:
if self.settings["general"]["reverse_timelines"] == False: self.db["sent_direct_messages"]["items"].append(i) if "sent_direct_messages" in self.db and utils.find_item(i.id, self.db["sent_direct_messages"]) == None:
else: self.db["sent_direct_messages"]["items"].insert(0, i) if self.settings["general"]["reverse_timelines"] == False: self.db["sent_direct_messages"].append(i)
else: self.db["sent_direct_messages"].insert(0, i)
sent = sent+1 sent = sent+1
else: else:
if utils.find_item(i["id"], self.db["direct_messages"]["items"]) == None: if utils.find_item(i.id, self.db["direct_messages"]) == None:
if self.settings["general"]["reverse_timelines"] == False: self.db["direct_messages"]["items"].append(i) if self.settings["general"]["reverse_timelines"] == False: self.db["direct_messages"].append(i)
else: self.db["direct_messages"]["items"].insert(0, i) else: self.db["direct_messages"].insert(0, i)
incoming = incoming+1 incoming = incoming+1
pub.sendMessage("sent-dms-updated", total=sent, account=self.db["user_name"]) pub.sendMessage("sent-dms-updated", total=sent, account=self.db["user_name"])
return incoming return incoming
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Session, self).__init__(*args, **kwargs) super(Session, self).__init__(*args, **kwargs)
# Adds here the optional cursors objects.
cursors = dict(direct_messages=-1)
self.db["cursors"] = cursors
self.reconnection_function_active = False self.reconnection_function_active = False
self.counter = 0 self.counter = 0
self.lists = [] self.lists = []
@ -115,7 +113,9 @@ class Session(base.baseSession):
if self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None: if self.settings["twitter"]["user_key"] != None and self.settings["twitter"]["user_secret"] != None:
try: try:
log.debug("Logging in to twitter...") log.debug("Logging in to twitter...")
self.twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"]) self.auth = tweepy.OAuthHandler(keyring.get("api_key"), keyring.get("api_secret"))
self.auth.set_access_token(self.settings["twitter"]["user_key"], self.settings["twitter"]["user_secret"])
self.twitter = tweepy.API(self.auth)
if verify_credentials == True: if verify_credentials == True:
self.credentials = self.twitter.verify_credentials() self.credentials = self.twitter.verify_credentials()
self.logged = True self.logged = True
@ -134,19 +134,18 @@ class Session(base.baseSession):
if self.logged == True: if self.logged == True:
raise Exceptions.AlreadyAuthorisedError("The authorisation process is not needed at this time.") raise Exceptions.AlreadyAuthorisedError("The authorisation process is not needed at this time.")
else: else:
twitter = Twython(keyring.get("api_key"), keyring.get("api_secret")) self.auth = tweepy.OAuthHandler(keyring.get("api_key"), keyring.get("api_secret"))
self.auth = twitter.get_authentication_tokens(callback_url="oob") redirect_url = self.auth.get_authorization_url()
webbrowser.open_new_tab(self.auth['auth_url']) webbrowser.open_new_tab(redirect_url)
self.authorisation_dialog = authorisationDialog() self.authorisation_dialog = authorisationDialog()
self.authorisation_dialog.cancel.Bind(wx.EVT_BUTTON, self.authorisation_cancelled) self.authorisation_dialog.cancel.Bind(wx.EVT_BUTTON, self.authorisation_cancelled)
self.authorisation_dialog.ok.Bind(wx.EVT_BUTTON, self.authorisation_accepted) self.authorisation_dialog.ok.Bind(wx.EVT_BUTTON, self.authorisation_accepted)
self.authorisation_dialog.ShowModal() self.authorisation_dialog.ShowModal()
def verify_authorisation(self, pincode): def verify_authorisation(self, pincode):
twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), self.auth['oauth_token'], self.auth['oauth_token_secret']) self.auth.get_access_token(pincode)
final = twitter.get_authorized_tokens(pincode) self.settings["twitter"]["user_key"] = self.auth.access_token
self.settings["twitter"]["user_key"] = final["oauth_token"] self.settings["twitter"]["user_secret"] = self.auth.access_token_secret
self.settings["twitter"]["user_secret"] = final["oauth_token_secret"]
self.settings.write() self.settings.write()
del self.auth del self.auth
@ -207,14 +206,14 @@ class Session(base.baseSession):
try: try:
val = getattr(self.twitter, call_name)(*args, **kwargs) val = getattr(self.twitter, call_name)(*args, **kwargs)
finished = True finished = True
except TwythonError as e: except TweepError as e:
output.speak(e.msg) output.speak(e.reason)
val = None val = None
if e.error_code != 403 and e.error_code != 404: if e.error_code != 403 and e.error_code != 404:
tries = tries+1 tries = tries+1
time.sleep(5) time.sleep(5)
elif report_failure and hasattr(e, 'message'): elif report_failure and hasattr(e, 'reason'):
output.speak(_("%s failed. Reason: %s") % (action, e.msg)) output.speak(_("%s failed. Reason: %s") % (action, e.reason))
finished = True finished = True
# except: # except:
# tries = tries + 1 # tries = tries + 1
@ -227,15 +226,15 @@ class Session(base.baseSession):
def search(self, name, *args, **kwargs): def search(self, name, *args, **kwargs):
""" Search in twitter, passing args and kwargs as arguments to the Twython function.""" """ Search in twitter, passing args and kwargs as arguments to the Twython function."""
tl = self.twitter.search(*args, **kwargs) tl = self.twitter.search(*args, **kwargs)
tl["statuses"].reverse() tl.reverse()
return tl["statuses"] return tl
# @_require_login # @_require_login
def get_favourites_timeline(self, name, *args, **kwargs): def get_favourites_timeline(self, name, *args, **kwargs):
""" Gets favourites for the authenticated user or a friend or follower. """ Gets favourites for the authenticated user or a friend or follower.
name str: Name for storage in the database. name str: Name for storage in the database.
args and kwargs are passed directly to the Twython function.""" args and kwargs are passed directly to the Twython function."""
tl = self.call_paged("get_favorites", *args, **kwargs) tl = self.call_paged("favorites", *args, **kwargs)
return self.order_buffer(name, tl) return self.order_buffer(name, tl)
def call_paged(self, update_function, *args, **kwargs): def call_paged(self, update_function, *args, **kwargs):
@ -249,8 +248,8 @@ class Session(base.baseSession):
data = getattr(self.twitter, update_function)(count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs) data = getattr(self.twitter, update_function)(count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs)
results.extend(data) results.extend(data)
for i in range(0, max): for i in range(0, max):
if i == 0: max_id = results[-1]["id"] if i == 0: max_id = results[-1].id
else: max_id = results[0]["id"] else: max_id = results[0].id
data = getattr(self.twitter, update_function)(max_id=max_id, count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs) data = getattr(self.twitter, update_function)(max_id=max_id, count=self.settings["general"]["max_tweets_per_call"], *args, **kwargs)
results.extend(data) results.extend(data)
results.reverse() results.reverse()
@ -259,11 +258,11 @@ class Session(base.baseSession):
# @_require_login # @_require_login
def get_user_info(self): def get_user_info(self):
""" Retrieves some information required by TWBlue for setup.""" """ Retrieves some information required by TWBlue for setup."""
f = self.twitter.get_account_settings() f = self.twitter.get_settings()
sn = f["screen_name"] sn = f["screen_name"]
self.settings["twitter"]["user_name"] = sn self.settings["twitter"]["user_name"] = sn
self.db["user_name"] = sn self.db["user_name"] = sn
self.db["user_id"] = self.twitter.show_user(screen_name=sn)["id_str"] self.db["user_id"] = self.twitter.get_user(screen_name=sn).id
try: try:
self.db["utc_offset"] = f["time_zone"]["utc_offset"] self.db["utc_offset"] = f["time_zone"]["utc_offset"]
except KeyError: except KeyError:
@ -271,7 +270,7 @@ class Session(base.baseSession):
# Get twitter's supported languages and save them in a global variable # Get twitter's supported languages and save them in a global variable
#so we won't call to this method once per session. #so we won't call to this method once per session.
if len(application.supported_languages) == 0: if len(application.supported_languages) == 0:
application.supported_languages = self.twitter.get_supported_languages() application.supported_languages = self.twitter.supported_languages()
self.get_lists() self.get_lists()
self.get_muted_users() self.get_muted_users()
self.settings.write() self.settings.write()
@ -279,12 +278,12 @@ class Session(base.baseSession):
# @_require_login # @_require_login
def get_lists(self): def get_lists(self):
""" Gets the lists that the user is subscribed to and stores them in the database. Returns None.""" """ Gets the lists that the user is subscribed to and stores them in the database. Returns None."""
self.db["lists"] = self.twitter.show_lists(reverse=True) self.db["lists"] = self.twitter.lists_all(reverse=True)
# @_require_login # @_require_login
def get_muted_users(self): def get_muted_users(self):
""" Gets muted users (oh really?).""" """ Gets muted users (oh really?)."""
self.db["muted_users"] = self.twitter.list_mute_ids()["ids"] self.db["muted_users"] = self.twitter.mutes_ids
# @_require_login # @_require_login
def get_stream(self, name, function, *args, **kwargs): def get_stream(self, name, function, *args, **kwargs):
@ -355,25 +354,25 @@ class Session(base.baseSession):
def get_quoted_tweet(self, tweet): def get_quoted_tweet(self, tweet):
""" Process a tweet and extract all information related to the quote.""" """ Process a tweet and extract all information related to the quote."""
quoted_tweet = tweet quoted_tweet = tweet
if "full_text" in tweet: if hasattr(tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
quoted_tweet[value] = utils.expand_urls(quoted_tweet[value], quoted_tweet["entities"]) setattr(quoted_tweet, value, utils.expand_urls(getattr(quoted_tweet, value), quoted_tweet.entities))
if "quoted_status" in quoted_tweet: if hasattr(quoted_tweet, "quoted_status"):
original_tweet = quoted_tweet["quoted_status"] original_tweet = quoted_tweet.quoted_status
elif "retweeted_status" in quoted_tweet and "quoted_status" in quoted_tweet["retweeted_status"]: elif hasattr(quoted_tweet, "retweeted_status") and hasattr(quoted_tweet.retweeted_status, "quoted_status"):
original_tweet = quoted_tweet["retweeted_status"]["quoted_status"] original_tweet = quoted_tweet.retweeted_status.quoted_status
else: else:
return quoted_tweet return quoted_tweet
original_tweet = self.check_long_tweet(original_tweet) original_tweet = self.check_long_tweet(original_tweet)
if "full_text" in original_tweet: if hasattr(original_tweet, "full_text"):
value = "full_text" value = "full_text"
elif "message" in original_tweet: elif hasattr(original_tweet, "message"):
value = "message" value = "message"
else: else:
value = "text" value = "text"
original_tweet[value] = utils.expand_urls(original_tweet[value], original_tweet["entities"]) setattr(original_tweet, value, utils.expand_urls(getattr(original_tweet, value), original_tweet.entities))
return compose.compose_quoted_tweet(quoted_tweet, original_tweet) return compose.compose_quoted_tweet(quoted_tweet, original_tweet)
def check_long_tweet(self, tweet): def check_long_tweet(self, tweet):
@ -383,22 +382,22 @@ class Session(base.baseSession):
long = twishort.is_long(tweet) long = twishort.is_long(tweet)
if long != False and config.app["app-settings"]["handle_longtweets"]: if long != False and config.app["app-settings"]["handle_longtweets"]:
message = twishort.get_full_text(long) message = twishort.get_full_text(long)
if "quoted_status" in tweet: if hasattr(tweet, "quoted_status"):
tweet["quoted_status"]["message"] = message tweet.quoted_status.message = message
if tweet["quoted_status"]["message"] == False: return False if tweet.quoted_status.message == False: return False
tweet["quoted_status"]["twishort"] = True tweet.quoted_status.twishort = True
for i in tweet["quoted_status"]["entities"]["user_mentions"]: for i in tweet.quoted_status.entities["user_mentions"]:
if "@%s" % (i["screen_name"]) not in tweet["quoted_status"]["message"] and i["screen_name"] != tweet["user"]["screen_name"]: if "@%s" % (i["screen_name"]) not in tweet.quoted_status.message and i["screen_name"] != tweet.user.screen_name:
if "retweeted_status" in tweet["quoted_status"] and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]: if hasattr(tweet["quoted_status"], "retweeted_status") and tweet.retweeted_status.user.screen_name == i["screen_name"]:
continue continue
tweet["quoted_status"]["message"] = u"@%s %s" % (i["screen_name"], tweet["message"]) tweet.quoted_status.message = u"@%s %s" % (i["screen_name"], tweet.message)
else: else:
tweet["message"] = message tweet.message = message
if tweet["message"] == False: return False if tweet.message == False: return False
tweet["twishort"] = True tweet.twishort = True
for i in tweet["entities"]["user_mentions"]: for i in tweet.entities["user_mentions"]:
if "@%s" % (i["screen_name"]) not in tweet["message"] and i["screen_name"] != tweet["user"]["screen_name"]: if "@%s" % (i["screen_name"]) not in tweet.message and i["screen_name"] != tweet.user.screen_name:
if "retweeted_status" in tweet and tweet["retweeted_status"]["user"]["screen_name"] == i["screen_name"]: if hasattr(tweet, "retweeted_status") and tweet.retweeted_status.user.screen_name == i["screen_name"]:
continue continue
return tweet return tweet
@ -408,11 +407,11 @@ class Session(base.baseSession):
returns an user dict.""" returns an user dict."""
if ("users" in self.db) == False or (id in self.db["users"]) == False: if ("users" in self.db) == False or (id in self.db["users"]) == False:
try: try:
user = self.twitter.show_user(id=id) user = self.twitter.get_user(id=id)
except TwythonError: except TweepError as err:
user = dict(screen_name="deleted_account", name="Deleted account") user = dict(screen_name="deleted_account", name="Deleted account")
return user return user
self.db["users"][user["id_str"]] = user self.db["users"][user.id_str] = user
return user return user
else: else:
return self.db["users"][id] return self.db["users"][id]
@ -427,8 +426,8 @@ class Session(base.baseSession):
return user["id_str"] return user["id_str"]
else: else:
for i in list(self.db["users"].keys()): for i in list(self.db["users"].keys()):
if self.db["users"][i]["screen_name"] == screen_name: if self.db["users"][i].screen_name == screen_name:
return self.db["users"][i]["id_str"] return self.db["users"][i].id_str
user = utils.if_user_exists(self.twitter, screen_name) user = utils.if_user_exists(self.twitter, screen_name)
self.db["users"][user["id_str"]] = user self.db["users"][user.id_str] = user
return user["id_str"] return user.id_str

View File

@ -1,16 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from builtins import str
from builtins import range
import url_shortener, re import url_shortener, re
import output import output
from twython import TwythonError
import config import config
import logging import logging
import requests import requests
import time import time
import sound import sound
from tweepy.error import TweepError
log = logging.getLogger("twitter.utils") log = logging.getLogger("twitter.utils")
""" Some utilities for the twitter interface.""" """ Some utilities for the twitter interface."""
@ -28,35 +24,35 @@ def find_urls_in_text(text):
def find_urls (tweet): def find_urls (tweet):
urls = [] urls = []
# Let's add URLS from tweet entities. # Let's add URLS from tweet entities.
if "message_create" in tweet: if hasattr(tweet, "message_create"):
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet.message_create["message_data"]["entities"]
else: else:
entities = tweet["entities"] entities = tweet.entities
for i in entities["urls"]: for i in entities["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if "quoted_status" in tweet: if hasattr(tweet, "quoted_status"):
for i in tweet["quoted_status"]["entities"]["urls"]: for i in tweet.quoted_status.entities["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
for i in tweet["retweeted_status"]["entities"]["urls"]: for i in tweet.retweeted_status.entities["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if "quoted_status" in tweet["retweeted_status"]: if hasattr(tweet["retweeted_status"], "quoted_status"):
for i in tweet["retweeted_status"]["quoted_status"]["entities"]["urls"]: for i in tweet.retweeted_status.quoted_status.entities["urls"]:
if i["expanded_url"] not in urls: if i["expanded_url"] not in urls:
urls.append(i["expanded_url"]) urls.append(i["expanded_url"])
if "message" in tweet: if hasattr(tweet, "message"):
i = "message" i = "message"
elif "full_text" in tweet: elif hasattr(tweet, "full_text"):
i = "full_text" i = "full_text"
else: else:
i = "text" i = "text"
if "message_create" in tweet: if hasattr(tweet, "message_create"):
extracted_urls = find_urls_in_text(tweet["message_create"]["message_data"]["text"]) extracted_urls = find_urls_in_text(tweet.message_create["message_data"]["text"])
else: else:
extracted_urls = find_urls_in_text(tweet[i]) extracted_urls = find_urls_in_text(getattr(tweet, i))
# Don't include t.co links (mostly they are photos or shortened versions of already added URLS). # Don't include t.co links (mostly they are photos or shortened versions of already added URLS).
for i in extracted_urls: for i in extracted_urls:
if i not in urls and "https://t.co" not in i: if i not in urls and "https://t.co" not in i:
@ -65,102 +61,103 @@ def find_urls (tweet):
def find_item(id, listItem): def find_item(id, listItem):
for i in range(0, len(listItem)): for i in range(0, len(listItem)):
if listItem[i]["id"] == id: return i if listItem[i].id == id: return i
return None return None
def find_list(name, lists): def find_list(name, lists):
for i in range(0, len(lists)): for i in range(0, len(lists)):
if lists[i]["name"] == name: return lists[i]["id"] if lists[i].name == name: return lists[i].id
def is_audio(tweet): def is_audio(tweet):
try: try:
if len(find_urls(tweet)) < 1: if len(find_urls(tweet)) < 1:
return False return False
if "message_create" in tweet: if hasattr(tweet, "message_create"):
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet.message_create["message_data"]["entities"]
else: else:
entities = tweet["entities"] entities = tweet.entities
if len(entities["hashtags"]) > 0: if len(entities["hashtags"]) > 0:
for i in entities["hashtags"]: for i in entities["hashtags"]:
if i["text"] == "audio": if i["text"] == "audio":
return True return True
except IndexError: except IndexError:
print(tweet["entities"]["hashtags"]) print(tweet.entities["hashtags"])
log.exception("Exception while executing is_audio hashtag algorithm") log.exception("Exception while executing is_audio hashtag algorithm")
def is_geocoded(tweet): def is_geocoded(tweet):
if "coordinates" in tweet and tweet["coordinates"] != None: if hasattr(tweet, "coordinates") and tweet.coordinates != None:
return True return True
def is_media(tweet): def is_media(tweet):
if "message_create" in tweet: if hasattr(tweet, "message_create"):
entities = tweet["message_create"]["message_data"]["entities"] entities = tweet.message_create["message_data"]["entities"]
else: else:
entities = tweet["entities"] entities = tweet.entities
if ("media" in entities) == False: if entities.get("media") == None:
return False return False
for i in entities["media"]: for i in entities["media"]:
if "type" in i and i["type"] == "photo": if i.get("type") != None and i.get("type") == "photo":
return True return True
return False return False
def get_all_mentioned(tweet, conf, field="screen_name"): def get_all_mentioned(tweet, conf, field="screen_name"):
""" Gets all users that have been mentioned.""" """ Gets all users that have been mentioned."""
results = [] results = []
for i in tweet["entities"]["user_mentions"]: for i in tweet.entities["user_mentions"]:
if i["screen_name"] != conf["user_name"] and i["screen_name"] != tweet["user"]["screen_name"]: if i["screen_name"] != conf["user_name"] and i["screen_name"] != tweet.user.screen_name:
if i[field] not in results: if i.get(field) not in results:
results.append(i[field]) results.append(i.get(field))
return results return results
def get_all_users(tweet, conf): def get_all_users(tweet, conf):
string = [] string = []
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
string.append(tweet["user"]["screen_name"]) string.append(tweet.user.screen_name)
tweet = tweet["retweeted_status"] tweet = tweet.retweeted_status
if "sender" in tweet: if hasattr(tweet, "sender"):
string.append(tweet["sender"]["screen_name"]) string.append(tweet.sender.screen_name)
else: else:
if tweet["user"]["screen_name"] != conf["user_name"]: if tweet.user.screen_name != conf["user_name"]:
string.append(tweet["user"]["screen_name"]) string.append(tweet.user.screen_name)
for i in tweet["entities"]["user_mentions"]: for i in tweet.entities["user_mentions"]:
if i["screen_name"] != conf["user_name"] and i["screen_name"] != tweet["user"]["screen_name"]: if i["screen_name"] != conf["user_name"] and i["screen_name"] != tweet.user.screen_name:
if i["screen_name"] not in string: if i["screen_name"] not in string:
string.append(i["screen_name"]) string.append(i["screen_name"])
if len(string) == 0: if len(string) == 0:
string.append(tweet["user"]["screen_name"]) string.append(tweet.user.screen_name)
return string return string
def if_user_exists(twitter, user): def if_user_exists(twitter, user):
try: try:
data = twitter.show_user(screen_name=user) data = twitter.get_user(screen_name=user)
return data return data
except TwythonError as err: except TweepError as err:
if err.error_code == 404: if err.api_code == 50:
return None return None
else: else:
return user return user
def is_allowed(tweet, settings, buffer_name): def is_allowed(tweet, settings, buffer_name):
clients = settings["twitter"]["ignored_clients"] clients = settings["twitter"]["ignored_clients"]
if "sender" in tweet: return True if hasattr(tweet, "sender"): return True
allowed = True allowed = True
tweet_data = {} tweet_data = {}
if "retweeted_status" in tweet: if hasattr(tweet, "retweeted_status"):
tweet_data["retweet"] = True tweet_data["retweet"] = True
if tweet["in_reply_to_status_id_str"] != None: if tweet.in_reply_to_status_id_str != None:
tweet_data["reply"] = True tweet_data["reply"] = True
if "quoted_status" in tweet: if hasattr(tweet, "quoted_status"):
tweet_data["quote"] = True tweet_data["quote"] = True
if "retweeted_status" in tweet: tweet = tweet["retweeted_status"] if hasattr(tweet, "retweeted_status"):
source = re.sub(r"(?s)<.*?>", "", tweet["source"]) tweet = tweet.retweeted_status
source = tweet.source
for i in clients: for i in clients:
if i.lower() == source.lower(): if i.lower() == source.lower():
return False return False
return filter_tweet(tweet, tweet_data, settings, buffer_name) return filter_tweet(tweet, tweet_data, settings, buffer_name)
def filter_tweet(tweet, tweet_data, settings, buffer_name): def filter_tweet(tweet, tweet_data, settings, buffer_name):
if "full_text" in tweet: if hasattr(tweet, "full_text"):
value = "full_text" value = "full_text"
else: else:
value = "text" value = "text"
@ -188,26 +185,26 @@ def filter_tweet(tweet, tweet_data, settings, buffer_name):
if allow_replies == "False" and "reply" in tweet_data: if allow_replies == "False" and "reply" in tweet_data:
return False return False
if word != "" and settings["filters"][i]["if_word_exists"]: if word != "" and settings["filters"][i]["if_word_exists"]:
if word in tweet[value]: if word in getattr(tweet, value):
return False return False
elif word != "" and settings["filters"][i]["if_word_exists"] == False: elif word != "" and settings["filters"][i]["if_word_exists"] == False:
if word not in tweet[value]: if word not in getattr(tweet, value):
return False return False
if settings["filters"][i]["in_lang"] == "True": if settings["filters"][i]["in_lang"] == "True":
if tweet["lang"] not in settings["filters"][i]["languages"]: if getattr(tweet, lang) not in settings["filters"][i]["languages"]:
return False return False
elif settings["filters"][i]["in_lang"] == "False": elif settings["filters"][i]["in_lang"] == "False":
if tweet["lang"] in settings["filters"][i]["languages"]: if tweet.lang in settings["filters"][i]["languages"]:
return False return False
return True return True
def twitter_error(error): def twitter_error(error):
if error.error_code == 403: if error.api_code == 179:
msg = _(u"Sorry, you are not authorised to see this status.") msg = _(u"Sorry, you are not authorised to see this status.")
elif error.error_code == 404: elif error.api_code == 144:
msg = _(u"No status found with that ID") msg = _(u"No status found with that ID")
else: else:
msg = _(u"Error code {0}").format(error.error_code,) msg = _(u"Error code {0}").format(error.api_code,)
output.speak(msg) output.speak(msg)
def expand_urls(text, entities): def expand_urls(text, entities):

View File

@ -41,7 +41,7 @@ class attachDialog(widgetUtils.BaseDialog):
return (openFileDialog.GetPath(), dsc) return (openFileDialog.GetPath(), dsc)
def ask_description(self): def ask_description(self):
dlg = wx.TextEntryDialog(self, _(u"please provide a description"), _(u"Description"), defaultValue="") dlg = wx.TextEntryDialog(self, _(u"please provide a description"), _(u"Description"))
dlg.ShowModal() dlg.ShowModal()
result = dlg.GetValue() result = dlg.GetValue()
dlg.Destroy() dlg.Destroy()

View File

@ -94,10 +94,10 @@ class editListDialog(createListDialog):
def __init__(self, list, *args, **kwargs): def __init__(self, list, *args, **kwargs):
super(editListDialog, self).__init__(*args, **kwargs) super(editListDialog, self).__init__(*args, **kwargs)
self.SetTitle(_(u"Editing the list %s") % (list["name"])) self.SetTitle(_(u"Editing the list %s") % (list.name))
self.name.ChangeValue(list["name"]) self.name.ChangeValue(list.name)
self.description.ChangeValue(list["description"]) self.description.ChangeValue(list.description)
if list["mode"] == "public": if list.mode == "public":
self.public.SetValue(True) self.public.SetValue(True)
else: else:
self.private.SetValue(True) self.private.SetValue(True)

View File

@ -1,7 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
# -*- coding: utf-8 -*-
from . import baseDialog from . import baseDialog
import wx import wx
@ -11,8 +8,7 @@ class trendingTopicsDialog(baseDialog.BaseWXDialog):
panel = wx.Panel(self) panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
self.SetTitle(_(u"View trending topics")) self.SetTitle(_(u"View trending topics"))
label = wx.StaticText(panel, -1, _(u"Trending topics by")) label = wx.StaticText(panel, wx.NewId(), _(u"Trending topics by"))
sizer.Add(label, 0, wx.ALL, 5)
self.country = wx.RadioButton(panel, -1, _(u"Country"), style=wx.RB_GROUP) self.country = wx.RadioButton(panel, -1, _(u"Country"), style=wx.RB_GROUP)
self.city = wx.RadioButton(panel, -1, _(u"City")) self.city = wx.RadioButton(panel, -1, _(u"City"))
radioSizer = wx.BoxSizer(wx.HORIZONTAL) radioSizer = wx.BoxSizer(wx.HORIZONTAL)