|
|
|
@ -118,6 +118,7 @@ class TwitterNetworkUser(NetworkUser):
|
|
|
|
|
convert twitter user information into a NetworkUser object.""" |
|
|
|
|
|
|
|
|
|
def __init__(self, data): |
|
|
|
|
super(TwitterNetworkUser, self).__init__() |
|
|
|
|
self.name = data['user']['name'] |
|
|
|
|
self.username = data['user']['screen_name'] |
|
|
|
|
self.avatar = data['user']['profile_image_url'] |
|
|
|
@ -127,14 +128,25 @@ class TwitterNetworkData(NetworkData):
|
|
|
|
|
"""A simple wrapper around NetworkData, to make things easier to convert |
|
|
|
|
twitter data into a NetworkData object.""" |
|
|
|
|
|
|
|
|
|
def __init__(self, data): |
|
|
|
|
def __init__(self, data, logged_user): |
|
|
|
|
"""Class initialization. Receives a dictionary with a single tweet.""" |
|
|
|
|
NetworkData.__init__(self) |
|
|
|
|
super(TwitterNetworkData, self).__init__() |
|
|
|
|
|
|
|
|
|
self.id = data['id'] |
|
|
|
|
self.author = TwitterNetworkUser(data) |
|
|
|
|
self.message_time = _to_datetime(data['created_at']) |
|
|
|
|
|
|
|
|
|
self.replyable = True # All messages are replyables |
|
|
|
|
self.favoritable = True # All messages are favoritable |
|
|
|
|
|
|
|
|
|
self.repostable = not (self.author.username == logged_user) |
|
|
|
|
self.deletable = (self.author.username == logged_user) |
|
|
|
|
|
|
|
|
|
self.link = 'http://twitter.com/%s/status/%s' % ( |
|
|
|
|
self.author.username, self.id) |
|
|
|
|
|
|
|
|
|
self.reply_prefx = '@' + self.author.username + ' ' |
|
|
|
|
|
|
|
|
|
if 'protected' in data['user']: |
|
|
|
|
# twitter protects all messages from a user, not per message. |
|
|
|
|
self.protected = data['user']['protected'] |
|
|
|
@ -411,18 +423,8 @@ class Connection(NetworkBase):
|
|
|
|
|
def message(self, message_id): |
|
|
|
|
"""Retrieves the information of one message.""" |
|
|
|
|
response = self._request('/statuses/show/%d.json' % (message_id)) |
|
|
|
|
return TwitterNetworkData(response) |
|
|
|
|
|
|
|
|
|
def link(self, message): |
|
|
|
|
"""Return a link directly to the message.""" |
|
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
|
return 'http://twitter.com/%s/status/%s' % (message.author.username, |
|
|
|
|
message.id) |
|
|
|
|
|
|
|
|
|
def reply_prefix(self, message): |
|
|
|
|
"""Returns the prefix needed for a reply.""" |
|
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
|
return '@' + message.author.username + ' ' |
|
|
|
|
return TwitterNetworkData(response, |
|
|
|
|
self._options[self.NAMESPACE]['username']) |
|
|
|
|
|
|
|
|
|
def replies(self): |
|
|
|
|
"""Return a list of NetworkData objects for the replies for the user |
|
|
|
@ -472,7 +474,8 @@ class Connection(NetworkBase):
|
|
|
|
|
# too large. |
|
|
|
|
# TODO: Some updates return the previous status, not the new one. Not |
|
|
|
|
# sure what that means. |
|
|
|
|
return TwitterNetworkData(data) |
|
|
|
|
return TwitterNetworkData(data, |
|
|
|
|
self._options[self.NAMESPACE]['username']) |
|
|
|
|
|
|
|
|
|
def repost(self, message): |
|
|
|
|
"""Repost a message.""" |
|
|
|
@ -480,7 +483,8 @@ class Connection(NetworkBase):
|
|
|
|
|
body = urllib.urlencode({'id': message.id}) |
|
|
|
|
resource = '/statuses/retweet/%d.json' % (message.id) |
|
|
|
|
data = self._request(resource, body=body) |
|
|
|
|
return TwitterNetworkData(data) |
|
|
|
|
return TwitterNetworkData(data, |
|
|
|
|
self._options[self.NAMESPACE]['username']) |
|
|
|
|
|
|
|
|
|
def favourite(self, message): |
|
|
|
|
"""Mark a message as favourite.""" |
|
|
|
@ -491,7 +495,8 @@ class Connection(NetworkBase):
|
|
|
|
|
else: |
|
|
|
|
resource = '/favorites/destroy/%d.json' % (message.id) |
|
|
|
|
data = self._request(resource, body=body) |
|
|
|
|
return TwitterNetworkData(data) |
|
|
|
|
return TwitterNetworkData(data, |
|
|
|
|
self._options[self.NAMESPACE]['username']) |
|
|
|
|
|
|
|
|
|
def delete_message(self, message): |
|
|
|
|
"""Delete a message.""" |
|
|
|
@ -505,25 +510,3 @@ class Connection(NetworkBase):
|
|
|
|
|
_log.debug('Delete response: %s', response) |
|
|
|
|
return True # Either we get a response or an exception before we reach |
|
|
|
|
# this. |
|
|
|
|
def can_delete(self, message): |
|
|
|
|
"""Check if the message belongs to the user. If so, returns True; |
|
|
|
|
False otherwise.""" |
|
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
|
return (message.author.username == |
|
|
|
|
self._options[self.NAMESPACE]['username']) |
|
|
|
|
|
|
|
|
|
def can_reply(self, message): |
|
|
|
|
"""Always return True; Twitter allows replying to any messages, |
|
|
|
|
including the ones from the user.""" |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
def can_repost(self, message): |
|
|
|
|
"""Twitter ignores retweets from the user.""" |
|
|
|
|
assert(isinstance(message, NetworkData)) |
|
|
|
|
return not (message.author.username == |
|
|
|
|
self._options[self.NAMESPACE]['username']) |
|
|
|
|
|
|
|
|
|
def can_favourite(self, message): |
|
|
|
|
"""Always return True; Twitter allows favouriting/unfavouriting any |
|
|
|
|
messages.""" |
|
|
|
|
return True |
|
|
|
|