3
BrightKite interface for Gwibber
4
SegPhault (Ryan Paul) - 10/19/2008
9
import urllib2, urllib, base64, re, simplejson
10
from xml.dom import minidom
31
NICK_PARSE = re.compile("@([A-Za-z0-9]+)")
34
def __init__(self, client, data):
36
self.account = client.account
37
self.service = client.account["service"]
38
self.username = client.account["username"]
40
self.sender = data["creator"]["fullname"]
41
self.sender_nick = data["creator"]["login"]
42
self.sender_id = data["creator"]["login"]
43
self.image = data["creator"]["small_avatar_url"]
45
self.time = support.parse_time(data["created_at"])
46
self.text = data["body"] or ""
47
self.bgcolor = "message_color"
50
self.url = "http://brightkite.com/objects/%s" % data["id"]
51
self.profile_url = "http://brightkite.com/people/%s" % self.sender_nick
53
self.html_string = '<span class="text">%s</span>' % \
54
NICK_PARSE.sub('@<a class="inlinenick" href="http://brightkite.com/people/\\1">\\1</a>',
55
support.linkify(self.text))
57
self.is_reply = ("@%s" % self.username) in self.text
58
self.can_thread = data["comments_count"] > 0
61
self.location_lon = data["place"]["longitude"]
62
self.location_lat = data["place"]["latitude"]
63
self.location_id = data["place"]["id"]
64
self.location_name = data["place"]["name"]
65
self.location_fullname = data["place"]["display_location"]
66
self.geo_position = (self.location_lat, self.location_lon)
69
self.thumbnails = [{"src": data["photo"], "href": data["photo"]}]
72
def __init__(self, client, data):
74
self.account = client.account
75
self.service = client.account["service"]
76
self.username = client.account["username"]
78
self.sender = data["user"]["fullname"]
79
self.sender_nick = data["user"]["login"]
80
self.sender_id = data["user"]["login"]
81
self.image = data["user"]["small_avatar_url"]
83
self.time = support.parse_time(data["created_at"])
84
self.text = data["comment"]
85
self.bgcolor = "message_color"
87
self.url = "http://brightkite.com/objects/%s" % data["place_object"]["id"]
88
self.profile_url = "http://brightkite.com/people/%s" % self.sender_nick
90
self.html_string = '<span class="text">%s</span>' % \
91
NICK_PARSE.sub('@<a class="inlinenick" href="http://brightkite.com/people/\\1">\\1</a>',
92
support.linkify(self.text))
94
self.is_reply = ("@%s" % self.username) in self.text
97
def __init__(self, client, data):
99
self.account = client.account
100
self.service = client.account["service"]
101
self.username = client.account["username"]
102
self.sender = data["fullname"]
103
self.sender_nick = data["login"]
104
self.sender_id = self.sender_nick
105
self.time = support.parse_time(data["last_checked_in"])
106
self.text = data["place"]["display_location"]
107
self.image = data["small_avatar_url"]
108
self.image_small = data["smaller_avatar_url"]
109
self.bgcolor = "message_color"
110
self.url = "http://brightkite.com" # TODO
111
self.profile_url = "http://brightkite.com" # TODO
112
self.is_reply = False
115
self.location_lon = data["place"]["longitude"]
116
self.location_lat = data["place"]["latitude"]
117
self.location_id = data["place"]["id"]
118
self.location_name = data["place"]["name"]
119
self.location_fullname = data["place"]["display_location"]
122
def __init__(self, acct):
126
return "Basic %s" % base64.encodestring(
127
("%s:%s" % (self.account["username"], self.account["password"]))).strip()
129
def connect(self, url, data = None):
130
return urllib2.urlopen(urllib2.Request(
131
url, data, {"Authorization": self.get_auth()}))
133
def get_friend_positions(self):
134
return simplejson.load(self.connect(
135
"http://brightkite.com/me/friends.json"))
137
def get_messages(self):
138
return simplejson.load(self.connect(
139
"http://brightkite.com/me/friendstream.json"))
141
def get_responses(self):
142
return simplejson.load(self.connect(
143
"http://brightkite.com/me/mentionsstream.json"))
145
def get_thread_data(self, msg):
146
return simplejson.load(self.connect(
147
"http://brightkite.com/objects/%s/comments.json" % msg.id))
149
def get_search(self, query):
150
return minidom.parseString(urllib2.urlopen(
151
urllib2.Request("http://identi.ca/search/notice/rss",
152
urllib.urlencode({"q": query}))).read()).getElementsByTagName("item")
154
def thread(self, msg):
156
for data in self.get_thread_data(msg):
157
yield Comment(self, data)
159
def friend_positions(self):
160
for data in self.get_friend_positions():
161
yield FriendPosition(self, data)
163
def search(self, query):
164
for data in self.get_search(query):
165
yield SearchResult(self, data, query)
168
for data in self.get_responses():
169
yield Message(self, data)
172
for data in self.get_messages():
173
yield Message(self, data)
175
def send(self, message):
176
return self.connect("http://identi.ca/api/statuses/update.json",
177
urllib.urlencode({"status":message}))