Replaced twython old exception handling by tweepy

This commit is contained in:
Manuel Cortez 2021-01-05 09:34:52 -06:00
parent 65ec231349
commit fa49637d0e

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,7 @@ 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 pubsub import pub from pubsub import pub
from sessions.twitter.long_tweets import twishort, tweets from sessions.twitter.long_tweets import twishort, tweets
@ -137,7 +134,7 @@ class baseBufferController(baseBuffers.buffer):
try: try:
tweet = self.session.twitter.get_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:
@ -148,7 +145,7 @@ class baseBufferController(baseBuffers.buffer):
try: try:
tweet = self.session.twitter.get_status(id=l, include_ext_alt_text=True) 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)
@ -202,8 +199,8 @@ class baseBufferController(baseBuffers.buffer):
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 = self.session.get_more_items(self.function, count=self.session.settings["general"]["max_tweets_per_call"], max_id=last_id, *self.args, **self.kwargs)
except TwythonError as e: except TweepError as e:
output.speak(e.message, True) output.speak(e.reason, True)
if items == None: if items == None:
return return
for i in items: for i in items:
@ -578,7 +575,7 @@ class baseBufferController(baseBuffers.buffer):
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
@ -615,8 +612,8 @@ class directMessagesController(baseBufferController):
def get_more_items(self): def get_more_items(self):
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 = 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)
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
@ -862,8 +859,8 @@ class peopleBufferController(baseBufferController):
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) 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)
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
@ -1008,8 +1005,8 @@ class searchBufferController(baseBufferController):
last_id = self.session.db[self.name][-1]["id"] last_id = self.session.db[self.name][-1]["id"]
try: try:
items = self.session.search(self.name, count=self.session.settings["general"]["max_tweets_per_call"], max_id=last_id, *self.args, **self.kwargs) 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: except TweepError as e:
output.speak(e.message, True) output.speak(e.reason, True)
if items == None: if items == None:
return return
for i in items: for i in items:
@ -1074,8 +1071,8 @@ 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
@ -1256,7 +1253,7 @@ class conversationBufferController(searchBufferController):
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.show_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"])