mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-01-31 05:10:45 -06:00
Implemented user profile viewer
This commit is contained in:
parent
a261365682
commit
33b6000b41
@ -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)
|
Loading…
x
Reference in New Issue
Block a user