mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-01-19 08:41:06 -06:00
Fixed user timeline creation
This commit is contained in:
parent
29a905199d
commit
93705bf534
@ -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
|
||||||
@ -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:
|
||||||
|
@ -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."""
|
||||||
|
|
||||||
@ -131,13 +127,12 @@ def get_all_users(tweet, conf):
|
|||||||
string.append(tweet.user.screen_name)
|
string.append(tweet.user.screen_name)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
# ToDo: implement this using tweepy
|
|
||||||
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.error_code == 50:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return user
|
return user
|
||||||
@ -204,12 +199,12 @@ def filter_tweet(tweet, tweet_data, settings, buffer_name):
|
|||||||
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.error_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):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user