43
47
def __init__(self, client, data):
45
49
self.client = client
46
50
self.account = client.account
47
51
self.protocol = client.account["protocol"]
48
52
self.username = client.account["username"]
53
self.bgcolor = "message_color"
54
self.id = data["id"] or ''
55
self.time = support.parse_time(data["created_at"])
56
self.is_private = False
51
59
user = data["user"]
59
67
self.sender = user["name"]
60
68
self.sender_nick = user["screen_name"]
61
69
self.sender_id = user["id"]
62
self.time = support.parse_time(data["created_at"])
63
self.text = data["text"]
64
self.image = user["profile_image_url"]
65
self.bgcolor = "message_color"
66
self.url = "https://twitter.com/%s/statuses/%s" % (user["screen_name"], data["id"])
67
self.profile_url = "https://twitter.com/%s" % user["screen_name"]
69
self.html_string = '<span class="text">%s</span>' % \
70
HASH_PARSE.sub('#<a class="inlinehash" href="gwibber:tag/\\1">\\1</a>',
71
NICK_PARSE.sub('@<a class="inlinenick" href="https://twitter.com/\\1">\\1</a>',
72
support.linkify(self.text)))
73
self.is_reply = re.compile("@%s[\W]+|@%s$" % (self.username, self.username)).search(self.text)
74
self.is_private = False
71
if data.has_key("user"):
72
self.sender = data["user"]["name"]
73
self.sender_nick = data["user"]["screen_name"]
74
self.sender_id = data["user"]["id"]
75
self.sender_location = data["user"]["location"]
76
self.sender_followers_count = data["user"]["followers_count"]
77
self.image = data["user"]["profile_image_url"]
78
self.url = "https://twitter.com/%s/statuses/%s" % (data["user"]["screen_name"], data["id"])
79
self.profile_url = "gwibber:user/%s" % data["user"]["screen_name"]
80
self.external_profile_url = "https://twitter.com/%s" % data["user"]["screen_name"]
82
if data.has_key("name"):
83
self.sender = data["name"]
84
self.sender_nick = data["screen_name"]
85
self.sender_id = data["id"]
86
self.sender_location = data["location"]
87
self.sender_followers_count = data["followers_count"]
88
self.image = data["profile_image_url"]
89
self.url = self.profile_url = self.external_profile_url = "https://twitter.com/%s" % data["screen_name"]
91
if data["protected"] == True:
92
self.text = _("This user has protected their updates.") + ' ' + _("You need to send a request before you can view this person's timeline.") + ' ' + _("Send request...")
93
self.html_string = '<p><b>' + _("This user has protected their updates.") + '</b><p>' + _("You need to send a request before you can view this person's timeline.") + '<p><a href="' + self.url + '">' + _("Send request...") + '</a>'
95
self.text = self.html_string = ''
97
if data.has_key("text"):
98
self.text = data["text"]
99
self.html_string = '<span class="text">%s</span>' % \
100
HASH_PARSE.sub('#<a class="inlinehash" href="gwibber:tag/\\1">\\1</a>',
101
NICK_PARSE.sub('@<a class="inlinenick" href="gwibber:user/\\1">\\1</a>',
102
support.linkify(self.text)))
103
self.is_reply = re.compile("@%s[\W]+|@%s$" % (self.username, self.username)).search(self.text)
107
if data.has_key("in_reply_to_screen_name"):
108
self.reply_nick = data["in_reply_to_screen_name"]
109
self.reply_url = "https://twitter.com/%s/statuses/%s" % (data["in_reply_to_screen_name"], data["in_reply_to_status_id"])
111
from traceback import format_exc
76
114
class SearchResult:
77
115
def __init__(self, client, data, query = None):
87
125
self.image = data["profile_image_url"]
88
126
self.bgcolor = "message_color"
89
127
self.url = "https://twitter.com/%s/statuses/%s" % (data["from_user"], data["id"])
90
self.profile_url = "https://twitter.com/%s" % data["from_user"]
128
self.profile_url = "gwibber:user/%s" % data["from_user"]
129
self.external_profile_url = "https://twitter.com/%s" % data["from_user"]
92
131
if query: html = support.highlight_search_results(self.text, query)
93
132
else: html = self.text
95
134
self.html_string = '<span class="text">%s</span>' % \
96
135
HASH_PARSE.sub('#<a class="inlinehash" href="gwibber:tag/\\1">\\1</a>',
97
NICK_PARSE.sub('@<a class="inlinenick" href="https://twitter.com/\\1">\\1</a>',
136
NICK_PARSE.sub('@<a class="inlinenick" href="gwibber:user/\\1">\\1</a>',
98
137
support.linkify(self.text)))
100
139
self.is_reply = re.compile("@%s[\W]+|@%s$" % (self.username, self.username)).search(self.text)
126
165
"https://twitter.com/statuses/friends_timeline.json",
127
166
urllib.urlencode({"count": self.account["receive_count"] or "20"})))
168
def get_user_messages(self, screen_name):
170
return simplejson.loads(self.connect(
171
"https://twitter.com/statuses/user_timeline/"+ screen_name + ".json",
172
urllib.urlencode({"count": self.account["receive_count"] or "20"})))
174
profile = [simplejson.loads(self.connect(
175
"https://twitter.com/users/show/"+ screen_name +".json"))]
129
178
def get_replies(self):
130
179
return simplejson.loads(self.connect(
131
180
"https://twitter.com/statuses/replies.json",
167
216
for data in self.get_messages():
168
217
yield Message(self, data)
219
def user_messages(self, screen_name):
220
for data in self.get_user_messages(screen_name):
221
yield Message(self, data)
170
223
def send(self, message):
171
224
data = simplejson.loads(self.connect(
172
225
"https://twitter.com/statuses/update.json",
173
urllib.urlencode({"status":message, "source": "gwibbernet"})))
226
urllib.urlencode({"status":message, "source": "gwibbernet"})))
174
227
return Message(self, data)
176
229
def send_thread(self, msg, message):