Merge lp:~seriy-pr/gwibber/vkontakte-ru-plugin into lp:gwibber
- vkontakte-ru-plugin
- Merge into trunk
Status: | Superseded | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~seriy-pr/gwibber/vkontakte-ru-plugin | ||||||||||||||||||||
Merge into: | lp:gwibber | ||||||||||||||||||||
Diff against target: |
1108 lines (+1041/-0) 8 files modified
.bzrignore (+3/-0) gwibber/microblog/plugins/vkontakte/__init__.py (+552/-0) gwibber/microblog/plugins/vkontakte/gtk/vkontakte/__init__.py (+162/-0) gwibber/microblog/plugins/vkontakte/ui/gwibber-accounts-vkontakte.ui (+182/-0) gwibber/microblog/plugins/vkontakte/vk_api_wrapper.py (+81/-0) gwibber/microblog/util/const.py (+2/-0) setup.py (+4/-0) ui/icons/breakdance/scalable/vkontakte.svg (+55/-0) |
||||||||||||||||||||
To merge this branch: | bzr merge lp:~seriy-pr/gwibber/vkontakte-ru-plugin | ||||||||||||||||||||
Related bugs: |
|
||||||||||||||||||||
Related blueprints: |
A button to "retweet" a microblog post.
(Undefined)
Vkontakte.ru support
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
gwibber-committers | Pending | ||
Review via email: mp+47651@code.launchpad.net |
This proposal has been superseded by a proposal from 2011-05-15.
Commit message
Description of the change
Added plugin for vkontakte.ru - most popular social network in Russia, Ukraine and many ex-USSR countries.
This branch contains a fix of whishlist bug #572753
Also there is a related blueprint https:/
Some peoples report that plugin works for them: https:/
- 961. By Sergey Prokhorov
-
Fix duplicate browser windows when try re-authorize
- 962. By Sergey Prokhorov
-
Merged with latest trunk
- 963. By Sergey Prokhorov
-
Merged with trunk
- 964. By Sergey Prokhorov
-
Code moved to new authorization method (OAuth2.0)
- 965. By Sergey Prokhorov
-
Fixed error with authorization (appears after migration to new API)
- 966. By Sergey Prokhorov
-
Merged with latest trunk
- 967. By Sergey Prokhorov
-
Add video/photo/links streams support + extra debug messages
- 968. By Sergey Prokhorov
-
Fix bug: "post comments doesn't loaded" + add declarative JSON structure description.
- 969. By Sergey Prokhorov
-
Simplify lazy loading mechanizm
- 970. By Sergey Prokhorov
-
Linkify comments and links description
- 971. By Sergey Prokhorov
-
Add mentions support
- 972. By Sergey Prokhorov
-
Fix notifications
- 973. By Sergey Prokhorov
-
Fix right-aligned text on "\ufeff" char appears on message
- 974. By Sergey Prokhorov
-
Add support for vkontakte hashtags.
- 975. By Sergey Prokhorov
-
Merged with trunk
- 976. By Sergey Prokhorov
-
Merged with head
- 977. By Sergey Prokhorov
-
merged with trunk
- 978. By Sergey Prokhorov
-
Make code less ugly + replace <br> with <br/>
- 979. By Sergey Prokhorov
-
merged with trunk
- 980. By Sergey Prokhorov
-
move icons to plugin directory
- 981. By Sergey Prokhorov
-
setup.py don't used in gwibber now
- 982. By Sergey Prokhorov
-
merged with trunk
- 983. By Sergey Prokhorov
-
Fix logging issue
- 984. By Sergey Prokhorov
-
Fix indentation
- 985. By Sergey Prokhorov
-
Fix logger issue
- 986. By Sergey Prokhorov
-
More logging fixes
- 987. By Sergey Prokhorov
-
fix code conventions
- 988. By Sergey Prokhorov
-
Fix issue of renaming the vk api wrapper
- 989. By Sergey Prokhorov
-
Fix indentation on gui module
- 990. By Sergey Prokhorov
-
Compatible with 3.3.92 on ubuntu 12.04
Unmerged revisions
- 990. By Sergey Prokhorov
-
Compatible with 3.3.92 on ubuntu 12.04
- 989. By Sergey Prokhorov
-
Fix indentation on gui module
- 988. By Sergey Prokhorov
-
Fix issue of renaming the vk api wrapper
- 987. By Sergey Prokhorov
-
fix code conventions
- 986. By Sergey Prokhorov
-
More logging fixes
- 985. By Sergey Prokhorov
-
Fix logger issue
- 984. By Sergey Prokhorov
-
Fix indentation
- 983. By Sergey Prokhorov
-
Fix logging issue
- 982. By Sergey Prokhorov
-
merged with trunk
- 981. By Sergey Prokhorov
-
setup.py don't used in gwibber now
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2008-12-27 22:52:45 +0000 | |||
3 | +++ .bzrignore 2011-05-15 21:54:31 +0000 | |||
4 | @@ -1,3 +1,6 @@ | |||
5 | 1 | gwibber/semantic.cache | 1 | gwibber/semantic.cache |
6 | 2 | semantic.cache | 2 | semantic.cache |
7 | 3 | *.mo | 3 | *.mo |
8 | 4 | ./.project | ||
9 | 5 | ./.pydevproject | ||
10 | 6 | ./.settings | ||
11 | 4 | 7 | ||
12 | === added directory 'gwibber/microblog/plugins/vkontakte' | |||
13 | === added file 'gwibber/microblog/plugins/vkontakte/__init__.py' | |||
14 | --- gwibber/microblog/plugins/vkontakte/__init__.py 1970-01-01 00:00:00 +0000 | |||
15 | +++ gwibber/microblog/plugins/vkontakte/__init__.py 2011-05-15 21:54:31 +0000 | |||
16 | @@ -0,0 +1,552 @@ | |||
17 | 1 | # -*- coding: utf-8 -*- | ||
18 | 2 | ''' | ||
19 | 3 | Created on 05.12.2010 | ||
20 | 4 | |||
21 | 5 | @author: Sergey Prokhorov <root@seriyps.ru> | ||
22 | 6 | ''' | ||
23 | 7 | import json | ||
24 | 8 | import inspect | ||
25 | 9 | from gwibber.microblog.util.const import * | ||
26 | 10 | from gwibber.microblog.util import log | ||
27 | 11 | from gwibber.microblog import util | ||
28 | 12 | import time | ||
29 | 13 | import urllib | ||
30 | 14 | from vk_api_wrapper import vk_api, vkException | ||
31 | 15 | # Try to import * from custom, install custom.py to include packaging | ||
32 | 16 | # customizations like distro API keys, etc | ||
33 | 17 | try: | ||
34 | 18 | from gwibber.microblog.util.custom import * | ||
35 | 19 | except: | ||
36 | 20 | pass | ||
37 | 21 | |||
38 | 22 | log.logger.name="Vkontakte" | ||
39 | 23 | |||
40 | 24 | VK_APP_ID="2036925"#XXX: remove me! see gwibber.microblog.util.const.VK_APP_ID | ||
41 | 25 | |||
42 | 26 | PROTOCOL_INFO={ | ||
43 | 27 | "name": "Vkontakte", | ||
44 | 28 | "version": "0.2", | ||
45 | 29 | |||
46 | 30 | "config": [ | ||
47 | 31 | "color", | ||
48 | 32 | "receive_enabled", | ||
49 | 33 | "receive_groups", | ||
50 | 34 | "send_enabled", | ||
51 | 35 | "username", | ||
52 | 36 | "uid", | ||
53 | 37 | "private:access_token" | ||
54 | 38 | ], | ||
55 | 39 | |||
56 | 40 | "authtype": "vkontakte", | ||
57 | 41 | "color": "#45688E", # #6D8FB3 | ||
58 | 42 | |||
59 | 43 | "features": [ | ||
60 | 44 | "send", | ||
61 | 45 | "reply", | ||
62 | 46 | "receive", | ||
63 | 47 | #"thread", | ||
64 | 48 | "delete", | ||
65 | 49 | #"send_thread", | ||
66 | 50 | "like", | ||
67 | 51 | "sincetime" | ||
68 | 52 | ], | ||
69 | 53 | |||
70 | 54 | "default_streams": [ | ||
71 | 55 | "receive", | ||
72 | 56 | "images", | ||
73 | 57 | "links", | ||
74 | 58 | "videos", | ||
75 | 59 | ] | ||
76 | 60 | } | ||
77 | 61 | |||
78 | 62 | URL_PREFIX='http://vkontakte.ru/' | ||
79 | 63 | |||
80 | 64 | class attachment_processor: | ||
81 | 65 | """Generate attachment fields | ||
82 | 66 | http://vkontakte.ru/developers.php?o=-1&p=%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5+%D0%BF%D0%BE%D0%BB%D1%8F+attachment | ||
83 | 67 | """ | ||
84 | 68 | |||
85 | 69 | def __init__(self, client): | ||
86 | 70 | self.client=client | ||
87 | 71 | |||
88 | 72 | def _process_photo(self, attachment): | ||
89 | 73 | return ("photo", | ||
90 | 74 | photoAttachment( | ||
91 | 75 | url="%sphoto%d_%d"%(URL_PREFIX, attachment["owner_id"], attachment["pid"]), | ||
92 | 76 | picture=attachment["src"])) | ||
93 | 77 | |||
94 | 78 | _process_posted_photo=_process_photo | ||
95 | 79 | |||
96 | 80 | def _process_graffiti(self, attachment): | ||
97 | 81 | return ("photo", | ||
98 | 82 | photoAttachment( | ||
99 | 83 | url="%sgraffiti%d?from_id=%d"%(URL_PREFIX, attachment["gid"], attachment["owner_id"]), | ||
100 | 84 | picture=attachment["src"])) | ||
101 | 85 | |||
102 | 86 | def _process_video(self, attachment): | ||
103 | 87 | lnk="%svideo%d_%d"%(URL_PREFIX, attachment["owner_id"], attachment["vid"]) | ||
104 | 88 | video_data=self.client.api.video.get(videos="%d_%d"%(attachment["owner_id"], attachment["vid"]))["response"] | ||
105 | 89 | return ("video", | ||
106 | 90 | videoAttachment( | ||
107 | 91 | url=lnk, | ||
108 | 92 | name=attachment["title"], | ||
109 | 93 | source=lnk, | ||
110 | 94 | picture=video_data[1]["image"])) | ||
111 | 95 | |||
112 | 96 | def _process_link(self, attachment): | ||
113 | 97 | l=linkAttachment( | ||
114 | 98 | name=attachment["title"], | ||
115 | 99 | url=attachment["url"], | ||
116 | 100 | description=attachment["description"]) | ||
117 | 101 | if attachment.has_key("image_src"): | ||
118 | 102 | l.picture=attachment["image_src"] | ||
119 | 103 | return "link", l | ||
120 | 104 | |||
121 | 105 | def process(self, attachment, message): | ||
122 | 106 | """find is processor has matched handler, and if yes, | ||
123 | 107 | generate attachment with this handler and merge it with | ||
124 | 108 | original message""" | ||
125 | 109 | type_=attachment["type"] | ||
126 | 110 | processor_name="_process_%s"%type_ | ||
127 | 111 | if hasattr(self, processor_name): | ||
128 | 112 | key, val=getattr(self, processor_name)(attachment[type_]) | ||
129 | 113 | setattr(message, key, val) | ||
130 | 114 | message.type=key | ||
131 | 115 | return message | ||
132 | 116 | |||
133 | 117 | |||
134 | 118 | ########### | ||
135 | 119 | # MAGICK!!! | ||
136 | 120 | ########### | ||
137 | 121 | '''vkontakte API don't return comments for wall posts, | ||
138 | 122 | but return comments count, so, we need download comments | ||
139 | 123 | for each posts with comments count > 0 by separate API query. | ||
140 | 124 | But, surprise! API don't return commenters profile data, only | ||
141 | 125 | commenter ID. That means, that we need download commenter profile | ||
142 | 126 | for each commenter. Only one good thing is that we can | ||
143 | 127 | download many profiles by single query. So, when process | ||
144 | 128 | wall posts, we insert "lasy_mask" fake objects in places, where | ||
145 | 129 | commenter profile must be. And ALL profiles loads only when | ||
146 | 130 | some slave object need profile data. | ||
147 | 131 | ''' | ||
148 | 132 | class lazy_master: | ||
149 | 133 | '''Dispatcher, that store slaves and start | ||
150 | 134 | worker when one of slaves need data''' | ||
151 | 135 | |||
152 | 136 | def __init__(self, worker): | ||
153 | 137 | ''' | ||
154 | 138 | @param worker: callback function, that do main work (convert | ||
155 | 139 | masks to results)''' | ||
156 | 140 | self.masks={} | ||
157 | 141 | self.results={} | ||
158 | 142 | self.worker=worker | ||
159 | 143 | |||
160 | 144 | def new_mask(self, id): | ||
161 | 145 | mask=lazy_mask(self, id) | ||
162 | 146 | self.masks[mask.id]=mask | ||
163 | 147 | return mask | ||
164 | 148 | |||
165 | 149 | def run(self): | ||
166 | 150 | #TODO: implement multiple run | ||
167 | 151 | self.results=self.worker(self.masks) | ||
168 | 152 | |||
169 | 153 | def get(self, id): | ||
170 | 154 | if not self.results:#.get(id, False): | ||
171 | 155 | self.run() | ||
172 | 156 | return self.results.get(id, None) | ||
173 | 157 | |||
174 | 158 | |||
175 | 159 | class lazy_mask(object): | ||
176 | 160 | '''Fake object, which is substituted in | ||
177 | 161 | place of masked object''' | ||
178 | 162 | |||
179 | 163 | def __init__(self, master, id): | ||
180 | 164 | self.master=master | ||
181 | 165 | self.id=id | ||
182 | 166 | self._result=None | ||
183 | 167 | |||
184 | 168 | def res(self): | ||
185 | 169 | '''Run lazy job''' | ||
186 | 170 | if not self._result: | ||
187 | 171 | self._result=self.master.get(self.id) | ||
188 | 172 | return self._result | ||
189 | 173 | |||
190 | 174 | ########### | ||
191 | 175 | # END MAGICK!!! | ||
192 | 176 | ########### | ||
193 | 177 | |||
194 | 178 | ########### | ||
195 | 179 | # declarative description of Gwibber message JSON structure | ||
196 | 180 | # XXX: this can/must be reused in other Gwibber plugins!!! | ||
197 | 181 | ########### | ||
198 | 182 | |||
199 | 183 | # base class | ||
200 | 184 | class jsonable(object): | ||
201 | 185 | """ | ||
202 | 186 | Allow subclass instances be represented as combination | ||
203 | 187 | of python std types (list, str, dict, int, float) that | ||
204 | 188 | can be used by json.dumps() | ||
205 | 189 | eg | ||
206 | 190 | ======================== | ||
207 | 191 | class C2(jsonable): | ||
208 | 192 | prop0="" | ||
209 | 193 | |||
210 | 194 | class C1(jsonable): | ||
211 | 195 | prop1="" # str | ||
212 | 196 | prop2=0 # int | ||
213 | 197 | prop3=0.0 # float | ||
214 | 198 | prop4={} # as is | ||
215 | 199 | prop5=("choice1", "choice2", "choice3") # one of | ||
216 | 200 | prop6=[C2, ] # list of | ||
217 | 201 | |||
218 | 202 | c1=C1(prop1="p1_val") # pass to constructor | ||
219 | 203 | c1.prop2=100500 # pass as property assignment | ||
220 | 204 | ... | ||
221 | 205 | prop5=[C2(prop0="c2_p0_val1"), C2(prop0="c2_p0_val2")] | ||
222 | 206 | |||
223 | 207 | >>> c1.to_jsonable() # return dict object | ||
224 | 208 | { | ||
225 | 209 | "prop1": "p1_val", | ||
226 | 210 | "prop2": 100500, | ||
227 | 211 | ... | ||
228 | 212 | "prop6":[ | ||
229 | 213 | { | ||
230 | 214 | "prop0": "c2_p0_val1" | ||
231 | 215 | }, | ||
232 | 216 | { | ||
233 | 217 | "prop0": "c2_p0_val2" | ||
234 | 218 | } | ||
235 | 219 | ] | ||
236 | 220 | } | ||
237 | 221 | =========================== | ||
238 | 222 | Idea came from http://code.google.com/p/gdata-python-client/source/browse/src/atom/core.py | ||
239 | 223 | "XmlElement" class | ||
240 | 224 | """ | ||
241 | 225 | _members=None | ||
242 | 226 | |||
243 | 227 | def __init__(self, **kwargs): | ||
244 | 228 | if self.__class__._members is None: | ||
245 | 229 | self.__class__._members=tuple(self.__class__._list_members()) | ||
246 | 230 | for member_name, member_type in self.__class__._members: | ||
247 | 231 | if member_name in kwargs: | ||
248 | 232 | setattr(self, member_name, kwargs[member_name]) | ||
249 | 233 | else: | ||
250 | 234 | if isinstance(member_type, list): | ||
251 | 235 | setattr(self, member_name, []) | ||
252 | 236 | else: | ||
253 | 237 | setattr(self, member_name, None) | ||
254 | 238 | |||
255 | 239 | @classmethod | ||
256 | 240 | def _list_members(cls): | ||
257 | 241 | """Introspect class properties""" | ||
258 | 242 | members=[] | ||
259 | 243 | for pair in inspect.getmembers(cls): | ||
260 | 244 | if not pair[0].startswith('_'): | ||
261 | 245 | member_type=pair[1] | ||
262 | 246 | if (isinstance(member_type, (tuple, list, str, unicode, dict, int, float, bool)) | ||
263 | 247 | or (inspect.isclass(member_type) | ||
264 | 248 | and issubclass(member_type, jsonable))): | ||
265 | 249 | members.append(pair) | ||
266 | 250 | return members | ||
267 | 251 | |||
268 | 252 | def to_jsonable(self): | ||
269 | 253 | """Recursively transform objects hierarchy to | ||
270 | 254 | hierarchy of python std types""" | ||
271 | 255 | res={} | ||
272 | 256 | for m_name, m_type in self._members: | ||
273 | 257 | child=getattr(self, m_name) | ||
274 | 258 | if child is None : | ||
275 | 259 | continue | ||
276 | 260 | if isinstance(m_type, (str, unicode)): | ||
277 | 261 | res[m_name]=unicode(child) | ||
278 | 262 | elif isinstance(m_type, int): | ||
279 | 263 | res[m_name]=int(child) | ||
280 | 264 | elif isinstance(m_type, float): | ||
281 | 265 | res[m_name]=float(child) | ||
282 | 266 | elif isinstance(m_type, bool): | ||
283 | 267 | res[m_name]=bool(child) | ||
284 | 268 | elif isinstance(m_type, dict): # copy as is | ||
285 | 269 | res[m_name]=child | ||
286 | 270 | elif isinstance(m_type, list): | ||
287 | 271 | res[m_name]=[] | ||
288 | 272 | for subchild in child: | ||
289 | 273 | res[m_name].append(subchild.to_jsonable()) | ||
290 | 274 | elif isinstance(m_type, tuple): | ||
291 | 275 | if child in m_type: | ||
292 | 276 | res[m_name]=child | ||
293 | 277 | elif inspect.isclass(m_type) and issubclass(m_type, jsonable): | ||
294 | 278 | res[m_name]=child.to_jsonable() # recursively | ||
295 | 279 | return res | ||
296 | 280 | |||
297 | 281 | def __str__(self): | ||
298 | 282 | return str(self.to_jsonable()) | ||
299 | 283 | |||
300 | 284 | # Gwibber message structure hierarchy: | ||
301 | 285 | |||
302 | 286 | class errMessage(jsonable): | ||
303 | 287 | type="" | ||
304 | 288 | account={} | ||
305 | 289 | message="" | ||
306 | 290 | |||
307 | 291 | class error(jsonable): | ||
308 | 292 | error=errMessage | ||
309 | 293 | |||
310 | 294 | class user(jsonable): | ||
311 | 295 | name="" | ||
312 | 296 | id="" | ||
313 | 297 | is_me=False | ||
314 | 298 | image="" | ||
315 | 299 | url="" | ||
316 | 300 | |||
317 | 301 | class lazyUserLoader(jsonable): | ||
318 | 302 | """Loads user profile only when to_json() called""" | ||
319 | 303 | def __init__(self, callback, **kwargs): | ||
320 | 304 | super(lazyUserLoader, self).__init__(**kwargs) | ||
321 | 305 | self._cb=callback | ||
322 | 306 | |||
323 | 307 | def to_jsonable(self): | ||
324 | 308 | res=self._cb.res() | ||
325 | 309 | return res.to_jsonable() if isinstance(res, jsonable) else {} | ||
326 | 310 | |||
327 | 311 | class like(jsonable): | ||
328 | 312 | count=0 | ||
329 | 313 | |||
330 | 314 | class photoAttachment(jsonable): | ||
331 | 315 | url="" | ||
332 | 316 | picture="" | ||
333 | 317 | |||
334 | 318 | class videoAttachment(jsonable): | ||
335 | 319 | url="" | ||
336 | 320 | name="" | ||
337 | 321 | source="" | ||
338 | 322 | picture="" | ||
339 | 323 | |||
340 | 324 | class linkAttachment(jsonable): | ||
341 | 325 | name="" | ||
342 | 326 | url="" | ||
343 | 327 | description="" | ||
344 | 328 | picture="" | ||
345 | 329 | |||
346 | 330 | class comment(jsonable): | ||
347 | 331 | text="" | ||
348 | 332 | time="" | ||
349 | 333 | sender=lazyUserLoader | ||
350 | 334 | |||
351 | 335 | class message(jsonable): | ||
352 | 336 | mid="" | ||
353 | 337 | service="" | ||
354 | 338 | account="" | ||
355 | 339 | time=0 | ||
356 | 340 | sender=user | ||
357 | 341 | url="" | ||
358 | 342 | text="" | ||
359 | 343 | html="" | ||
360 | 344 | content="" | ||
361 | 345 | likes=like | ||
362 | 346 | photo=photoAttachment | ||
363 | 347 | video=videoAttachment | ||
364 | 348 | link=linkAttachment | ||
365 | 349 | type=("photo", "video", "link") | ||
366 | 350 | comments=[comment, ] | ||
367 | 351 | |||
368 | 352 | ########### | ||
369 | 353 | # END declarative description of Gwibber message JSON structure | ||
370 | 354 | ########### | ||
371 | 355 | |||
372 | 356 | class Client: | ||
373 | 357 | |||
374 | 358 | def __init__(self, acct): | ||
375 | 359 | self.account=acct | ||
376 | 360 | self.access_token=acct.get("access_token") | ||
377 | 361 | self.api=vk_api(access_token=self.access_token) | ||
378 | 362 | self.attachment_processor=attachment_processor(self) | ||
379 | 363 | |||
380 | 364 | def __call__(self, opname, **args): | ||
381 | 365 | try: | ||
382 | 366 | ret=[item for item in getattr(self, opname)(**args) if isinstance(item, jsonable)] # read all yield's | ||
383 | 367 | #for i in ret: | ||
384 | 368 | # print str(i) | ||
385 | 369 | return [item.to_jsonable() for item in ret] | ||
386 | 370 | except vkException, e: | ||
387 | 371 | return [self._format_error(e).to_jsonable()] | ||
388 | 372 | |||
389 | 373 | def _format_error(self, e, type=None, message=None): | ||
390 | 374 | log.logger.error('Vkontakte error #%d: "%s" in url %s', e.code, e.msg, e.url) | ||
391 | 375 | if e.code in (3, 5, 7): | ||
392 | 376 | _type="auth" | ||
393 | 377 | #elif e.code in (2, 4, 100): | ||
394 | 378 | # _type="internal" | ||
395 | 379 | else: | ||
396 | 380 | _type="unknown" | ||
397 | 381 | return error(error=errMessage(type=type or _type, | ||
398 | 382 | account=self.account, | ||
399 | 383 | message=message or e.msg)) | ||
400 | 384 | |||
401 | 385 | def _user(self, acc_data): | ||
402 | 386 | """Extract single user data from API response""" | ||
403 | 387 | if acc_data.has_key("gid"): | ||
404 | 388 | return user(name=acc_data["name"], | ||
405 | 389 | id=str(acc_data["gid"]*-1), | ||
406 | 390 | is_me=False, | ||
407 | 391 | image=acc_data["photo"], | ||
408 | 392 | url="%sclub%s"%(URL_PREFIX, acc_data["gid"])) | ||
409 | 393 | else: | ||
410 | 394 | return user(name="%s %s"%(acc_data["first_name"], acc_data["last_name"]), | ||
411 | 395 | id=str(acc_data["uid"]), | ||
412 | 396 | is_me=acc_data["uid"]==int(self.account["uid"]), | ||
413 | 397 | image=acc_data["photo"], | ||
414 | 398 | url="%sid%s"%(URL_PREFIX, acc_data["uid"])) | ||
415 | 399 | |||
416 | 400 | def _message(self, item, account, comment_author_factory): | ||
417 | 401 | """Extract single message data from API response""" | ||
418 | 402 | m=message() | ||
419 | 403 | m.mid=str(item["post_id"]) | ||
420 | 404 | m.service="vkontakte" | ||
421 | 405 | m.account=self.account["id"] | ||
422 | 406 | m.time=item["date"]+time.timezone # XXX: WTF?!? why we don't move timezone correction to presentation logic??? We must store to DB absolute UTC timestamp!!! | ||
423 | 407 | m.sender=self._user(account) | ||
424 | 408 | m.url="%swall%s_%s"%(URL_PREFIX, m.sender.id, item["post_id"]) | ||
425 | 409 | m.text=item["text"] | ||
426 | 410 | m.html=util.linkify(item["text"], escape=False) | ||
427 | 411 | m.content=m.html | ||
428 | 412 | |||
429 | 413 | if item.get("likes", 0): | ||
430 | 414 | m.likes=like(count=item["likes"]["count"]) | ||
431 | 415 | |||
432 | 416 | if item.has_key("attachment"): | ||
433 | 417 | if item["attachment"]["type"]=="audio": | ||
434 | 418 | return#FIXME: Gwibber don't support audio | ||
435 | 419 | m=self.attachment_processor.process(item["attachment"], m) | ||
436 | 420 | |||
437 | 421 | if item["comments"]["count"]>0: | ||
438 | 422 | try: | ||
439 | 423 | comments=self.api.wall.getComments(owner_id=m.sender.id, | ||
440 | 424 | post_id=item["post_id"], | ||
441 | 425 | sort="asc", | ||
442 | 426 | count=50) | ||
443 | 427 | except vkException, e: | ||
444 | 428 | return self._format_error(e) # XXX: may be return "m" ? | ||
445 | 429 | if comments.has_key("response"): | ||
446 | 430 | for comm in comments["response"]: | ||
447 | 431 | if not isinstance(comm, dict):#drop first(?) element, because it is integer count of comments | ||
448 | 432 | continue | ||
449 | 433 | mask=comment_author_factory.new_mask(comm["uid"]) | ||
450 | 434 | m.comments.append( | ||
451 | 435 | comment( | ||
452 | 436 | text=comm["text"], | ||
453 | 437 | time=comm["date"], | ||
454 | 438 | sender=lazyUserLoader(mask) | ||
455 | 439 | ) | ||
456 | 440 | ) | ||
457 | 441 | return m | ||
458 | 442 | |||
459 | 443 | def _get_lazy_profiles_factory(self): | ||
460 | 444 | def lazy_comment_profiles_loader(slaves): | ||
461 | 445 | '''magick (see comments upper) lazy worker (transform map of | ||
462 | 446 | profile id's to map of profiles)''' | ||
463 | 447 | ids=[]#slaves.keys() | ||
464 | 448 | for slave in slaves.itervalues(): | ||
465 | 449 | ids.append(str(slave.id)) | ||
466 | 450 | uids=",".join(ids) | ||
467 | 451 | try: | ||
468 | 452 | profiles=self.api.getProfiles(uids=uids, fields="uid,photo,first_name,last_name") | ||
469 | 453 | except vkException, e: | ||
470 | 454 | self._format_error(e)#log message to console | ||
471 | 455 | return {} | ||
472 | 456 | res={} | ||
473 | 457 | for profile in profiles['response']: | ||
474 | 458 | res[profile["uid"]]=self._user(profile) | ||
475 | 459 | return res | ||
476 | 460 | |||
477 | 461 | return lazy_master(worker=lazy_comment_profiles_loader) | ||
478 | 462 | |||
479 | 463 | def receive(self, since=None): | ||
480 | 464 | '''Retrieve messages from friend's and own walls.''' | ||
481 | 465 | if not since: | ||
482 | 466 | since=int(time.time()-60*60*24)#24 hours | ||
483 | 467 | response=self.api.newsfeed.get(filters="post", start_time=since)["response"] | ||
484 | 468 | |||
485 | 469 | comment_author_factory=self._get_lazy_profiles_factory() | ||
486 | 470 | |||
487 | 471 | profiles_by_id={}#index user and group profiles by user id | ||
488 | 472 | for _acc in response["profiles"]: | ||
489 | 473 | profiles_by_id[_acc["uid"]]=_acc | ||
490 | 474 | if self.account["receive_groups"]: | ||
491 | 475 | for _acc in response["groups"]: | ||
492 | 476 | profiles_by_id[_acc["gid"]*-1]=_acc | ||
493 | 477 | for item in response["items"]: | ||
494 | 478 | if item["source_id"]<0 and not self.account["receive_groups"]:#source_id > 0 for peoples and < 0 for groups | ||
495 | 479 | continue#skip groups if "receive_groups" option disabled | ||
496 | 480 | account=profiles_by_id[item["source_id"]] | ||
497 | 481 | message=self._message(item, account, comment_author_factory) | ||
498 | 482 | yield message | ||
499 | 483 | for msg in self._own_wall_posts(5, comment_author_factory): | ||
500 | 484 | yield msg | ||
501 | 485 | |||
502 | 486 | def _own_wall_posts(self, count, comment_author_factory): | ||
503 | 487 | '''Download all posts user post in own wall''' | ||
504 | 488 | try: | ||
505 | 489 | response=self.api.wall.get(filter="owner", count=count)["response"] | ||
506 | 490 | except vkException, e: | ||
507 | 491 | yield self._format_error(e) | ||
508 | 492 | return | ||
509 | 493 | me=None | ||
510 | 494 | for post in response: | ||
511 | 495 | if not isinstance(post, dict):#skip first element - number of items | ||
512 | 496 | continue | ||
513 | 497 | post["post_id"]=post["id"] | ||
514 | 498 | post["source_id"]=post["from_id"] | ||
515 | 499 | if not me: | ||
516 | 500 | me=self.api.getProfiles(uids=post["source_id"], fields="uid,photo,first_name,last_name")["response"][0] | ||
517 | 501 | yield self._message(post, me, comment_author_factory) | ||
518 | 502 | |||
519 | 503 | def user_messages(self, id=None, count=util.COUNT, since=None): | ||
520 | 504 | """Messages posted by some user""" | ||
521 | 505 | raise NotImplementedError | ||
522 | 506 | if count>100:#vk limit | ||
523 | 507 | count=100 | ||
524 | 508 | comment_author_factory=self._get_lazy_profiles_factory() | ||
525 | 509 | return self._own_wall_posts(count, comment_author_factory) | ||
526 | 510 | |||
527 | 511 | def send(self, message): | ||
528 | 512 | """Send new post to own wall""" | ||
529 | 513 | self.api.wall.post(message=message) | ||
530 | 514 | return self._own_wall_posts(1, self._get_lazy_profiles_factory()) | ||
531 | 515 | |||
532 | 516 | def send_thread(self, message, target): | ||
533 | 517 | """Send comment with text @message to post @target | ||
534 | 518 | @param message: message text | ||
535 | 519 | @param target: target post""" | ||
536 | 520 | self.api.wall.addComment(owner_id=target["sender"]["id"], | ||
537 | 521 | post_id=target["mid"], | ||
538 | 522 | text=message) | ||
539 | 523 | # Update post data | ||
540 | 524 | # XXX: this doesn't update Gwibber UI and this is a Gwibber bug... | ||
541 | 525 | return self._post_by_id(target["sender"]["id"], target["mid"]) | ||
542 | 526 | |||
543 | 527 | def _post_by_id(self, owner_id, post_id): | ||
544 | 528 | response=self.api.wall.getById(posts="%s_%s"%(owner_id, post_id))["response"] | ||
545 | 529 | comment_author_factory=self._get_lazy_profiles_factory() | ||
546 | 530 | me=None | ||
547 | 531 | for post in response: | ||
548 | 532 | if not isinstance(post, dict):#skip first element - number of items | ||
549 | 533 | continue | ||
550 | 534 | post["post_id"]=post["id"] | ||
551 | 535 | post["source_id"]=post["from_id"] | ||
552 | 536 | if not me: | ||
553 | 537 | me=self.api.getProfiles(uids=post["source_id"], fields="uid,photo,first_name,last_name")["response"][0] | ||
554 | 538 | yield self._message(post, me, comment_author_factory) | ||
555 | 539 | |||
556 | 540 | def like(self, message): | ||
557 | 541 | """Like message | ||
558 | 542 | @param message: target post you like""" | ||
559 | 543 | self.api.wall.addLike(owner_id=message["sender"]["id"], | ||
560 | 544 | post_id=message["mid"]) | ||
561 | 545 | return [] | ||
562 | 546 | |||
563 | 547 | def delete(self, message): | ||
564 | 548 | """Remove message from you wall | ||
565 | 549 | @param message: post you want to delete""" | ||
566 | 550 | self.api.wall.delete(owner_id=message["sender"]["id"], | ||
567 | 551 | post_id=message["mid"]) | ||
568 | 552 | return [] | ||
569 | 0 | 553 | ||
570 | === added directory 'gwibber/microblog/plugins/vkontakte/gtk' | |||
571 | === added file 'gwibber/microblog/plugins/vkontakte/gtk/__init__.py' | |||
572 | === added directory 'gwibber/microblog/plugins/vkontakte/gtk/vkontakte' | |||
573 | === added file 'gwibber/microblog/plugins/vkontakte/gtk/vkontakte/__init__.py' | |||
574 | --- gwibber/microblog/plugins/vkontakte/gtk/vkontakte/__init__.py 1970-01-01 00:00:00 +0000 | |||
575 | +++ gwibber/microblog/plugins/vkontakte/gtk/vkontakte/__init__.py 2011-05-15 21:54:31 +0000 | |||
576 | @@ -0,0 +1,162 @@ | |||
577 | 1 | |||
578 | 2 | import gtk | ||
579 | 3 | from gwibber.microblog.util import resources | ||
580 | 4 | from gwibber.microblog.util.const import * | ||
581 | 5 | try: | ||
582 | 6 | from gwibber.microblog.plugins.vkontakte.vk_api_wrapper import vk_api | ||
583 | 7 | except ImportError: | ||
584 | 8 | try: | ||
585 | 9 | from vkontakte.vk_api_wrapper import vk_api | ||
586 | 10 | except ImportError: | ||
587 | 11 | vk_api=None | ||
588 | 12 | |||
589 | 13 | import gnomekeyring | ||
590 | 14 | import webkit | ||
591 | 15 | import urllib | ||
592 | 16 | import urlparse | ||
593 | 17 | |||
594 | 18 | import gettext | ||
595 | 19 | from gettext import gettext as _ | ||
596 | 20 | if hasattr(gettext, 'bind_textdomain_codeset'): | ||
597 | 21 | gettext.bind_textdomain_codeset('gwibber', 'UTF-8') | ||
598 | 22 | gettext.textdomain('gwibber') | ||
599 | 23 | |||
600 | 24 | VK_APP_ID="2036925"#XXX: remove me! see gwibber.microblog.util.const.VK_APP_ID | ||
601 | 25 | |||
602 | 26 | class AccountWidget(gtk.VBox): | ||
603 | 27 | """AccountWidget: A widget that provides a user interface for configuring | ||
604 | 28 | Vkontakte accounts in Gwibber""" | ||
605 | 29 | |||
606 | 30 | def __init__(self, account=None, dialog=None): | ||
607 | 31 | """Creates the account pane for configuring Vkontakte accounts""" | ||
608 | 32 | gtk.VBox.__init__(self, False, 20) | ||
609 | 33 | self._state_init() | ||
610 | 34 | if account: | ||
611 | 35 | self.account=account | ||
612 | 36 | else: | ||
613 | 37 | self.account={} | ||
614 | 38 | self.dialog=dialog | ||
615 | 39 | has_access_token=True | ||
616 | 40 | if self.account.has_key("id"):#check is current account already authorized | ||
617 | 41 | try: | ||
618 | 42 | _value=gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, {"id": str("%s/%s"%(self.account["id"], "access_token"))})[0].secret | ||
619 | 43 | except gnomekeyring.NoMatchError: | ||
620 | 44 | has_access_token=False | ||
621 | 45 | try:#if account authorized, don't show "authorize" button | ||
622 | 46 | if self.account["access_token"] and self.account["username"] and has_access_token and not self.dialog.condition: | ||
623 | 47 | self._state_authorized() | ||
624 | 48 | else:#else don't show "authorized" label | ||
625 | 49 | self._state_not_authorized() | ||
626 | 50 | except: | ||
627 | 51 | self._state_not_authorized() | ||
628 | 52 | |||
629 | 53 | |||
630 | 54 | def on_vk_auth_clicked(self, widget, data=None): | ||
631 | 55 | """Start embed browser and show authorization dialog""" | ||
632 | 56 | web=webkit.WebView() | ||
633 | 57 | web.get_settings().set_property("enable-plugins", False) | ||
634 | 58 | web.load_html_string(_("<p>Please wait...</p>"), "file:///") | ||
635 | 59 | |||
636 | 60 | qstring=urllib.urlencode({#call to vkontakte API authorization | ||
637 | 61 | "client_id": VK_APP_ID, | ||
638 | 62 | "redirect_uri": "http://vkontakte.ru/api/login_success.html", #FIXME: http://api.vkontakte.ru/blank.html don't fire "title-changed" | ||
639 | 63 | "response_type": "token", | ||
640 | 64 | "display": "popup", | ||
641 | 65 | "scope": ",".join(("video", "offline", "wall")) | ||
642 | 66 | }) | ||
643 | 67 | web.set_size_request(550, 440) | ||
644 | 68 | web.load_uri("http://api.vkontakte.ru/oauth/authorize?"+qstring) | ||
645 | 69 | #http://api.vkontakte.ru/oauth/authorize?client_id=2036925&response_type=token&scope=video,offline,wal&redirect_uri=http://api.vkontakte.ru/blank.html | ||
646 | 70 | web.connect("title-changed", self.on_vk_auth_title_change) | ||
647 | 71 | self._state_show_browser(web) | ||
648 | 72 | |||
649 | 73 | def on_vk_auth_title_change(self, web=None, title=None, data=None): | ||
650 | 74 | """When user confirm or revoke authorization in embed browser""" | ||
651 | 75 | saved=False | ||
652 | 76 | url=web.get_main_frame().get_uri() | ||
653 | 77 | if "access_token=" in url: | ||
654 | 78 | """When user successfully authorize our application, extract access_token secret... | ||
655 | 79 | http://api.vkontakte.ru/blank.html#access_token=55a69...c55&expires_in=0&user_id=535...7""" | ||
656 | 80 | query_string=url.split("#", 1)[1] | ||
657 | 81 | data=urlparse.parse_qs(query_string) | ||
658 | 82 | self.account["access_token"]=str(data["access_token"][0]) | ||
659 | 83 | self.account["uid"]=data["user_id"][0] | ||
660 | 84 | if vk_api:#try retrieve user name and last name from API | ||
661 | 85 | profile=vk_api(access_token=self.account["access_token"]).getProfiles(uids=self.account["uid"], | ||
662 | 86 | fields="first_name,last_name") | ||
663 | 87 | self.account["username"]=u"%(first_name)s %(last_name)s"%(profile['response'][0]) | ||
664 | 88 | else: | ||
665 | 89 | self.account["username"]="id%s"%self.account["uid"] | ||
666 | 90 | saved=self.dialog.on_edit_account_save()#store user account data | ||
667 | 91 | self._state_authorized() | ||
668 | 92 | self._state_login_success(saved) | ||
669 | 93 | self._state_hide_browser(web) | ||
670 | 94 | if "error=" in url: | ||
671 | 95 | query_string=url.split("?", 1)[1] | ||
672 | 96 | desc=urlparse.parse_qs(query_string)["error_description"][0] | ||
673 | 97 | self._state_not_authorized() | ||
674 | 98 | self._state_login_failed(_("Authentication error: %s")%desc) | ||
675 | 99 | self._state_hide_browser(web) | ||
676 | 100 | |||
677 | 101 | ### UI-manipulation methods ### | ||
678 | 102 | |||
679 | 103 | def _state_init(self): | ||
680 | 104 | """create UI from UI file""" | ||
681 | 105 | self._browser_scroll=None | ||
682 | 106 | self.ui=gtk.Builder() | ||
683 | 107 | self.ui.set_translation_domain("gwibber") | ||
684 | 108 | self.ui.add_from_file(resources.get_ui_asset("gwibber-accounts-vkontakte.ui")) | ||
685 | 109 | self.ui.connect_signals(self)#attach events (on_vk_auth_clicked) | ||
686 | 110 | self.vbox_settings=self.ui.get_object("vbox_settings") | ||
687 | 111 | self.pack_start(self.vbox_settings, False, False) | ||
688 | 112 | self.show_all() | ||
689 | 113 | |||
690 | 114 | def _state_show_browser(self, web): | ||
691 | 115 | """Show webkit widget, hide settings etc..""" | ||
692 | 116 | (self.win_w, self.win_h)=self.window.get_size() | ||
693 | 117 | if not self._browser_scroll: | ||
694 | 118 | self._browser_scroll=gtk.ScrolledWindow() | ||
695 | 119 | self.pack_start(self._browser_scroll, True, True, 0) | ||
696 | 120 | self._browser_scroll.child=None | ||
697 | 121 | self._browser_scroll.add(web) | ||
698 | 122 | self.show_all() | ||
699 | 123 | self.ui.get_object("vbox1").hide() | ||
700 | 124 | self.ui.get_object("vbox_advanced").hide() | ||
701 | 125 | |||
702 | 126 | def _state_hide_browser(self, web): | ||
703 | 127 | """Hide webkit, show advanced settings, etc..""" | ||
704 | 128 | web.hide() | ||
705 | 129 | self.window.resize(self.win_w, self.win_h) | ||
706 | 130 | self.ui.get_object("vbox1").show() | ||
707 | 131 | self.ui.get_object("vbox_advanced").show() | ||
708 | 132 | |||
709 | 133 | def _state_login_success(self, saved): | ||
710 | 134 | """Show 'update' or 'create' buttons if not saved automatically""" | ||
711 | 135 | if self.dialog.ui and self.account.has_key("id") and not saved: | ||
712 | 136 | self.dialog.ui.get_object("vbox_save").show() | ||
713 | 137 | elif self.dialog.ui and not saved: | ||
714 | 138 | self.dialog.ui.get_object("vbox_create").show() | ||
715 | 139 | |||
716 | 140 | def _state_login_failed(self, reason=None): | ||
717 | 141 | """When user fail or revoke authorization, show popup message""" | ||
718 | 142 | gtk.gdk.threads_enter() | ||
719 | 143 | if not reason: | ||
720 | 144 | reason=_("Vkontakte authorization failed. Please try again.") | ||
721 | 145 | else: | ||
722 | 146 | reason=_(reason) | ||
723 | 147 | d=gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, reason) | ||
724 | 148 | if d.run(): d.destroy() | ||
725 | 149 | gtk.gdk.threads_leave() | ||
726 | 150 | |||
727 | 151 | def _state_not_authorized(self): | ||
728 | 152 | """Show 'Authorize with vkontakte' button""" | ||
729 | 153 | self.ui.get_object("hbox_vk_auth_done").hide() | ||
730 | 154 | self.ui.get_object("hbox_vk_auth").show() | ||
731 | 155 | if self.dialog.ui: | ||
732 | 156 | self.dialog.ui.get_object('vbox_create').hide() | ||
733 | 157 | |||
734 | 158 | def _state_authorized(self): | ||
735 | 159 | """Hide 'Authorize with vkontakte' button, show 'Authorized'""" | ||
736 | 160 | self.ui.get_object("hbox_vk_auth").hide() | ||
737 | 161 | self.ui.get_object("vk_auth_done_label").set_label(_("%s has been authorized by Vkontakte")%str(self.account["username"])) | ||
738 | 162 | self.ui.get_object("hbox_vk_auth_done").show() | ||
739 | 0 | 163 | ||
740 | === added directory 'gwibber/microblog/plugins/vkontakte/ui' | |||
741 | === added file 'gwibber/microblog/plugins/vkontakte/ui/gwibber-accounts-vkontakte.ui' | |||
742 | --- gwibber/microblog/plugins/vkontakte/ui/gwibber-accounts-vkontakte.ui 1970-01-01 00:00:00 +0000 | |||
743 | +++ gwibber/microblog/plugins/vkontakte/ui/gwibber-accounts-vkontakte.ui 2011-05-15 21:54:31 +0000 | |||
744 | @@ -0,0 +1,182 @@ | |||
745 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
746 | 2 | <interface> | ||
747 | 3 | <requires lib="gtk+" version="2.16"/> | ||
748 | 4 | <!-- interface-naming-policy toplevel-contextual --> | ||
749 | 5 | <object class="GtkVBox" id="vbox_settings"> | ||
750 | 6 | <property name="visible">True</property> | ||
751 | 7 | <property name="spacing">6</property> | ||
752 | 8 | <child> | ||
753 | 9 | <object class="GtkVBox" id="vbox1"> | ||
754 | 10 | <property name="visible">True</property> | ||
755 | 11 | <child> | ||
756 | 12 | <object class="GtkHBox" id="hbox_vk_auth"> | ||
757 | 13 | <property name="visible">True</property> | ||
758 | 14 | <child> | ||
759 | 15 | <object class="GtkButton" id="vk_auth_button"> | ||
760 | 16 | <property name="label" translatable="yes">_Authorize</property> | ||
761 | 17 | <property name="visible">True</property> | ||
762 | 18 | <property name="can_focus">True</property> | ||
763 | 19 | <property name="receives_default">True</property> | ||
764 | 20 | <property name="use_underline">True</property> | ||
765 | 21 | <signal name="clicked" handler="on_vk_auth_clicked"/> | ||
766 | 22 | </object> | ||
767 | 23 | <packing> | ||
768 | 24 | <property name="fill">False</property> | ||
769 | 25 | <property name="position">0</property> | ||
770 | 26 | </packing> | ||
771 | 27 | </child> | ||
772 | 28 | <child> | ||
773 | 29 | <object class="GtkLabel" id="vk_auth_label"> | ||
774 | 30 | <property name="visible">True</property> | ||
775 | 31 | <property name="label" translatable="yes">Authorize with vkontakte</property> | ||
776 | 32 | </object> | ||
777 | 33 | <packing> | ||
778 | 34 | <property name="position">1</property> | ||
779 | 35 | </packing> | ||
780 | 36 | </child> | ||
781 | 37 | </object> | ||
782 | 38 | <packing> | ||
783 | 39 | <property name="position">0</property> | ||
784 | 40 | </packing> | ||
785 | 41 | </child> | ||
786 | 42 | <child> | ||
787 | 43 | <object class="GtkHBox" id="hbox_vk_auth_done"> | ||
788 | 44 | <property name="visible">True</property> | ||
789 | 45 | <child> | ||
790 | 46 | <object class="GtkLabel" id="vk_auth_done_label"> | ||
791 | 47 | <property name="visible">True</property> | ||
792 | 48 | <property name="label" translatable="yes">Vkontakte authorized</property> | ||
793 | 49 | </object> | ||
794 | 50 | <packing> | ||
795 | 51 | <property name="position">0</property> | ||
796 | 52 | </packing> | ||
797 | 53 | </child> | ||
798 | 54 | </object> | ||
799 | 55 | <packing> | ||
800 | 56 | <property name="position">1</property> | ||
801 | 57 | </packing> | ||
802 | 58 | </child> | ||
803 | 59 | </object> | ||
804 | 60 | <packing> | ||
805 | 61 | <property name="position">0</property> | ||
806 | 62 | </packing> | ||
807 | 63 | </child> | ||
808 | 64 | <child> | ||
809 | 65 | <object class="GtkHSeparator" id="hseparator1"> | ||
810 | 66 | <property name="visible">True</property> | ||
811 | 67 | </object> | ||
812 | 68 | <packing> | ||
813 | 69 | <property name="expand">False</property> | ||
814 | 70 | <property name="position">1</property> | ||
815 | 71 | </packing> | ||
816 | 72 | </child> | ||
817 | 73 | <child> | ||
818 | 74 | <object class="GtkVBox" id="vbox_advanced"> | ||
819 | 75 | <property name="visible">True</property> | ||
820 | 76 | <property name="spacing">6</property> | ||
821 | 77 | <child> | ||
822 | 78 | <object class="GtkLabel" id="label3"> | ||
823 | 79 | <property name="visible">True</property> | ||
824 | 80 | <property name="xalign">0</property> | ||
825 | 81 | <property name="label" translatable="yes">Account Settings:</property> | ||
826 | 82 | <attributes> | ||
827 | 83 | <attribute name="weight" value="bold"/> | ||
828 | 84 | </attributes> | ||
829 | 85 | </object> | ||
830 | 86 | <packing> | ||
831 | 87 | <property name="position">0</property> | ||
832 | 88 | </packing> | ||
833 | 89 | </child> | ||
834 | 90 | <child> | ||
835 | 91 | <object class="GtkVBox" id="vbox2"> | ||
836 | 92 | <property name="visible">True</property> | ||
837 | 93 | <child> | ||
838 | 94 | <object class="GtkCheckButton" id="receive_enabled"> | ||
839 | 95 | <property name="label" translatable="yes">_Receive Messages</property> | ||
840 | 96 | <property name="visible">True</property> | ||
841 | 97 | <property name="can_focus">True</property> | ||
842 | 98 | <property name="receives_default">False</property> | ||
843 | 99 | <property name="tooltip_text" translatable="yes">Include this account when downloading messages</property> | ||
844 | 100 | <property name="use_underline">True</property> | ||
845 | 101 | <property name="active">True</property> | ||
846 | 102 | <property name="draw_indicator">True</property> | ||
847 | 103 | </object> | ||
848 | 104 | <packing> | ||
849 | 105 | <property name="position">0</property> | ||
850 | 106 | </packing> | ||
851 | 107 | </child> | ||
852 | 108 | <child> | ||
853 | 109 | <object class="GtkCheckButton" id="send_enabled"> | ||
854 | 110 | <property name="label" translatable="yes">_Send Messages</property> | ||
855 | 111 | <property name="visible">True</property> | ||
856 | 112 | <property name="can_focus">True</property> | ||
857 | 113 | <property name="receives_default">False</property> | ||
858 | 114 | <property name="tooltip_text" translatable="yes">Allow sending posts to this account</property> | ||
859 | 115 | <property name="use_underline">True</property> | ||
860 | 116 | <property name="active">True</property> | ||
861 | 117 | <property name="draw_indicator">True</property> | ||
862 | 118 | </object> | ||
863 | 119 | <packing> | ||
864 | 120 | <property name="position">1</property> | ||
865 | 121 | </packing> | ||
866 | 122 | </child> | ||
867 | 123 | <child> | ||
868 | 124 | <object class="GtkCheckButton" id="receive_groups"> | ||
869 | 125 | <property name="label" translatable="yes" comments="Receive messages from the groups, in addition to messages from users?">_Receive groups</property> | ||
870 | 126 | <property name="visible">True</property> | ||
871 | 127 | <property name="can_focus">True</property> | ||
872 | 128 | <property name="receives_default">False</property> | ||
873 | 129 | <property name="tooltip_text" translatable="yes">Receive news from groups</property> | ||
874 | 130 | <property name="use_underline">True</property> | ||
875 | 131 | <property name="active">True</property> | ||
876 | 132 | <property name="draw_indicator">True</property> | ||
877 | 133 | </object> | ||
878 | 134 | <packing> | ||
879 | 135 | <property name="position">2</property> | ||
880 | 136 | </packing> | ||
881 | 137 | </child> | ||
882 | 138 | </object> | ||
883 | 139 | <packing> | ||
884 | 140 | <property name="position">1</property> | ||
885 | 141 | </packing> | ||
886 | 142 | </child> | ||
887 | 143 | <child> | ||
888 | 144 | <object class="GtkHBox" id="hbox1"> | ||
889 | 145 | <property name="visible">True</property> | ||
890 | 146 | <property name="homogeneous">True</property> | ||
891 | 147 | <child> | ||
892 | 148 | <object class="GtkLabel" id="label4"> | ||
893 | 149 | <property name="visible">True</property> | ||
894 | 150 | <property name="tooltip_text" translatable="yes">Color used to help distinguish accounts</property> | ||
895 | 151 | <property name="xalign">0</property> | ||
896 | 152 | <property name="label" translatable="yes">Account Color:</property> | ||
897 | 153 | </object> | ||
898 | 154 | <packing> | ||
899 | 155 | <property name="position">0</property> | ||
900 | 156 | </packing> | ||
901 | 157 | </child> | ||
902 | 158 | <child> | ||
903 | 159 | <object class="GtkColorButton" id="color"> | ||
904 | 160 | <property name="visible">True</property> | ||
905 | 161 | <property name="can_focus">True</property> | ||
906 | 162 | <property name="receives_default">True</property> | ||
907 | 163 | <property name="tooltip_text" translatable="yes">Color used to help distinguish accounts</property> | ||
908 | 164 | <property name="color">#000000000000</property> | ||
909 | 165 | </object> | ||
910 | 166 | <packing> | ||
911 | 167 | <property name="expand">False</property> | ||
912 | 168 | <property name="position">1</property> | ||
913 | 169 | </packing> | ||
914 | 170 | </child> | ||
915 | 171 | </object> | ||
916 | 172 | <packing> | ||
917 | 173 | <property name="position">2</property> | ||
918 | 174 | </packing> | ||
919 | 175 | </child> | ||
920 | 176 | </object> | ||
921 | 177 | <packing> | ||
922 | 178 | <property name="position">2</property> | ||
923 | 179 | </packing> | ||
924 | 180 | </child> | ||
925 | 181 | </object> | ||
926 | 182 | </interface> | ||
927 | 0 | 183 | ||
928 | === added file 'gwibber/microblog/plugins/vkontakte/vk_api_wrapper.py' | |||
929 | --- gwibber/microblog/plugins/vkontakte/vk_api_wrapper.py 1970-01-01 00:00:00 +0000 | |||
930 | +++ gwibber/microblog/plugins/vkontakte/vk_api_wrapper.py 2011-05-15 21:54:31 +0000 | |||
931 | @@ -0,0 +1,81 @@ | |||
932 | 1 | # -*- coding: utf-8 -*- | ||
933 | 2 | ''' | ||
934 | 3 | Created on 07.12.2010 | ||
935 | 4 | |||
936 | 5 | @author: Sergey Prokhorov <root@seriyps.ru> | ||
937 | 6 | ''' | ||
938 | 7 | from gwibber.microblog import network | ||
939 | 8 | from gwibber.microblog.util import log | ||
940 | 9 | import urllib | ||
941 | 10 | import time | ||
942 | 11 | |||
943 | 12 | class vkException(Exception): | ||
944 | 13 | |||
945 | 14 | def __init__(self, code, msg, url, response): | ||
946 | 15 | self.code=code | ||
947 | 16 | self.msg=msg | ||
948 | 17 | self.response=response | ||
949 | 18 | self.url=url | ||
950 | 19 | Exception.__init__(self, code, msg, url, response) | ||
951 | 20 | |||
952 | 21 | |||
953 | 22 | class vk_api: | ||
954 | 23 | """Vkontakte.ru (vk.com) API wrapper for Gwibber | ||
955 | 24 | == Usage == | ||
956 | 25 | Initialization: | ||
957 | 26 | api=vk_api(access_token) | ||
958 | 27 | "access_token" can be retrieved from call to http://api.vkontakte.ru/oauth/authorize | ||
959 | 28 | (see http://vkontakte.ru/developers.php?o=-1&p=%C0%E2%F2%EE%F0%E8%E7%E0%F6%E8%FF%20%EA%EB%E8%E5%ED%F2%F1%EA%E8%F5%20%EF%F0%E8%EB%EE%E6%E5%ED%E8%E9) | ||
960 | 29 | Make calls to simple methods (has no dots in name, like "getProfiles", "isAppUser"): | ||
961 | 30 | res=api.method(arg_name1=arg1, arg_name2=arg2) | ||
962 | 31 | eg res=api.getProfiles(uids="535397,1", fields="uid,first_name,last_name") | ||
963 | 32 | Make calls to namespaced methods (has dots in name, like "wall.post", "newsfeed.get"): | ||
964 | 33 | res=api.namespace.method(arg_name1=arg1, arg_name2=arg2) | ||
965 | 34 | eg res=api.wall.post(message="New wall post from API") | ||
966 | 35 | Alternative call syntax (better performance): | ||
967 | 36 | res=api._load('namespace.method', arg_name1=arg1, arg_name2=arg2) | ||
968 | 37 | eg res=api._get('wall.post', message="New wall post from API") | ||
969 | 38 | """ | ||
970 | 39 | |||
971 | 40 | api_url='https://api.vkontakte.ru/method/%s' | ||
972 | 41 | |||
973 | 42 | def __init__(self, access_token): | ||
974 | 43 | self._access_token=access_token | ||
975 | 44 | self._prefix=[] | ||
976 | 45 | |||
977 | 46 | def _load(self, method, **params): | ||
978 | 47 | """Make call by method name and arguments""" | ||
979 | 48 | params["access_token"]=self._access_token | ||
980 | 49 | url=self.api_url%method | ||
981 | 50 | for _i in xrange(3):#this cycle used for API error #6 "Too many requests" | ||
982 | 51 | log.logger.debug("Perform API request to method %s. URL: %s?%s", method, url, urllib.urlencode(params)) | ||
983 | 52 | res=network.Download(url, params, False).get_json() | ||
984 | 53 | if not res.has_key("error"): | ||
985 | 54 | #log.logger.debug("%s"%res) | ||
986 | 55 | return res | ||
987 | 56 | |||
988 | 57 | if res["error"]["error_code"]!=6: | ||
989 | 58 | break | ||
990 | 59 | log.logging.warning('Error #6 "%s". Wait 0.5s and retry...', res["error"]["error_msg"]) | ||
991 | 60 | '''if we get error #6 "Too many requests per second" (vk allow | ||
992 | 61 | max 3rps http://vkontakte.ru/developers.php?o=-1&p=%D0%92%D0%B7%D0%B0%D0%B8%D0%BC%D0%BE%D0%B4%D0%B5%D0%B9%D1%81%D1%82%D0%B2%D0%B8%D0%B5+%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D1%8F+%D1%81+API ) | ||
993 | 62 | try to sleep with small delay and retry request not more then 3x times''' | ||
994 | 63 | time.sleep(0.5)#TODO: play with sleep value | ||
995 | 64 | raise vkException(res["error"]["error_code"], | ||
996 | 65 | res["error"]["error_msg"], | ||
997 | 66 | "%s?%s"%(url, urllib.urlencode(params)), | ||
998 | 67 | res) | ||
999 | 68 | |||
1000 | 69 | |||
1001 | 70 | """Support for api.namespace.method(**kwargs) calls below""" | ||
1002 | 71 | def __getattr__(self, name): | ||
1003 | 72 | self._prefix.append(name) | ||
1004 | 73 | return self | ||
1005 | 74 | |||
1006 | 75 | def __call__(self, **kwargs): | ||
1007 | 76 | if self._prefix: | ||
1008 | 77 | method=".".join(self._prefix) | ||
1009 | 78 | self._prefix=[] | ||
1010 | 79 | else: | ||
1011 | 80 | method=kwargs.pop("method") | ||
1012 | 81 | return self._load(method, **kwargs) | ||
1013 | 0 | 82 | ||
1014 | === modified file 'gwibber/microblog/util/const.py' | |||
1015 | --- gwibber/microblog/util/const.py 2011-04-22 15:53:40 +0000 | |||
1016 | +++ gwibber/microblog/util/const.py 2011-05-15 21:54:31 +0000 | |||
1017 | @@ -15,6 +15,8 @@ | |||
1018 | 15 | TWITTER_OAUTH_KEY = "VDOuA5qCJ1XhjaSa4pl76g" | 15 | TWITTER_OAUTH_KEY = "VDOuA5qCJ1XhjaSa4pl76g" |
1019 | 16 | TWITTER_OAUTH_SECRET = "BqHlB8sMz5FhZmmFimwgiIdB0RiBr72Y0bio49IVJM" | 16 | TWITTER_OAUTH_SECRET = "BqHlB8sMz5FhZmmFimwgiIdB0RiBr72Y0bio49IVJM" |
1020 | 17 | 17 | ||
1021 | 18 | VK_APP_ID="2036925" | ||
1022 | 19 | |||
1023 | 18 | # Gwibber | 20 | # Gwibber |
1024 | 19 | MAX_MESSAGE_LENGTH = 140 | 21 | MAX_MESSAGE_LENGTH = 140 |
1025 | 20 | MAX_MESSAGE_COUNT = 20000 | 22 | MAX_MESSAGE_COUNT = 20000 |
1026 | 21 | 23 | ||
1027 | === modified file 'setup.py' | |||
1028 | --- setup.py 2011-04-22 16:12:39 +0000 | |||
1029 | +++ setup.py 2011-05-15 21:54:31 +0000 | |||
1030 | @@ -34,6 +34,10 @@ | |||
1031 | 34 | ('share/gwibber/plugins/facebook/gtk', glob("gwibber/microblog/plugins/facebook/gtk/*.*")), | 34 | ('share/gwibber/plugins/facebook/gtk', glob("gwibber/microblog/plugins/facebook/gtk/*.*")), |
1032 | 35 | ('share/gwibber/plugins/facebook/gtk/facebook', glob("gwibber/microblog/plugins/facebook/gtk/facebook/*.*")), | 35 | ('share/gwibber/plugins/facebook/gtk/facebook', glob("gwibber/microblog/plugins/facebook/gtk/facebook/*.*")), |
1033 | 36 | ('share/gwibber/plugins/facebook/ui', glob("gwibber/microblog/plugins/facebook/ui/*.*")), | 36 | ('share/gwibber/plugins/facebook/ui', glob("gwibber/microblog/plugins/facebook/ui/*.*")), |
1034 | 37 | ('share/gwibber/plugins/vkontakte', glob("gwibber/microblog/plugins/vkontakte/*.*")), | ||
1035 | 38 | ('share/gwibber/plugins/vkontakte/gtk', glob("gwibber/microblog/plugins/vkontakte/gtk/*.*")), | ||
1036 | 39 | ('share/gwibber/plugins/vkontakte/gtk/vkontakte', glob("gwibber/microblog/plugins/vkontakte/gtk/vkontakte/*.*")), | ||
1037 | 40 | ('share/gwibber/plugins/vkontakte/ui', glob("gwibber/microblog/plugins/vkontakte/ui/*.*")), | ||
1038 | 37 | ('share/gwibber/plugins/flickr', glob("gwibber/microblog/plugins/flickr/*.*")), | 41 | ('share/gwibber/plugins/flickr', glob("gwibber/microblog/plugins/flickr/*.*")), |
1039 | 38 | ('share/gwibber/plugins/flickr/gtk', glob("gwibber/microblog/plugins/flickr/gtk/*.*")), | 42 | ('share/gwibber/plugins/flickr/gtk', glob("gwibber/microblog/plugins/flickr/gtk/*.*")), |
1040 | 39 | ('share/gwibber/plugins/flickr/gtk/flickr', glob("gwibber/microblog/plugins/flickr/gtk/flickr/*.*")), | 43 | ('share/gwibber/plugins/flickr/gtk/flickr', glob("gwibber/microblog/plugins/flickr/gtk/flickr/*.*")), |
1041 | 40 | 44 | ||
1042 | === added file 'ui/icons/breakdance/16x16/vkontakte.png' | |||
1043 | 41 | Binary files ui/icons/breakdance/16x16/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/16x16/vkontakte.png 2011-05-15 21:54:31 +0000 differ | 45 | Binary files ui/icons/breakdance/16x16/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/16x16/vkontakte.png 2011-05-15 21:54:31 +0000 differ |
1044 | === added file 'ui/icons/breakdance/22x22/vkontakte.png' | |||
1045 | 42 | Binary files ui/icons/breakdance/22x22/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/22x22/vkontakte.png 2011-05-15 21:54:31 +0000 differ | 46 | Binary files ui/icons/breakdance/22x22/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/22x22/vkontakte.png 2011-05-15 21:54:31 +0000 differ |
1046 | === added file 'ui/icons/breakdance/32x32/vkontakte.png' | |||
1047 | 43 | Binary files ui/icons/breakdance/32x32/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/32x32/vkontakte.png 2011-05-15 21:54:31 +0000 differ | 47 | Binary files ui/icons/breakdance/32x32/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/32x32/vkontakte.png 2011-05-15 21:54:31 +0000 differ |
1048 | === added file 'ui/icons/breakdance/scalable/vkontakte.png' | |||
1049 | 44 | Binary files ui/icons/breakdance/scalable/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/scalable/vkontakte.png 2011-05-15 21:54:31 +0000 differ | 48 | Binary files ui/icons/breakdance/scalable/vkontakte.png 1970-01-01 00:00:00 +0000 and ui/icons/breakdance/scalable/vkontakte.png 2011-05-15 21:54:31 +0000 differ |
1050 | === added file 'ui/icons/breakdance/scalable/vkontakte.svg' | |||
1051 | --- ui/icons/breakdance/scalable/vkontakte.svg 1970-01-01 00:00:00 +0000 | |||
1052 | +++ ui/icons/breakdance/scalable/vkontakte.svg 2011-05-15 21:54:31 +0000 | |||
1053 | @@ -0,0 +1,55 @@ | |||
1054 | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
1055 | 2 | <!-- Created with Inkscape (http://www.inkscape.org/) --> | ||
1056 | 3 | <!-- SVG Created by Sergey A Prochorov <root@seriyps.ru> (http://seriyps.ru/) --> | ||
1057 | 4 | <svg | ||
1058 | 5 | xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
1059 | 6 | xmlns:cc="http://creativecommons.org/ns#" | ||
1060 | 7 | xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
1061 | 8 | xmlns:svg="http://www.w3.org/2000/svg" | ||
1062 | 9 | xmlns="http://www.w3.org/2000/svg" | ||
1063 | 10 | version="1.1" | ||
1064 | 11 | width="285" | ||
1065 | 12 | height="285" | ||
1066 | 13 | id="svg3036"> | ||
1067 | 14 | <defs | ||
1068 | 15 | id="defs8"> | ||
1069 | 16 | <filter | ||
1070 | 17 | color-interpolation-filters="sRGB" | ||
1071 | 18 | id="filter3773"> | ||
1072 | 19 | <feGaussianBlur | ||
1073 | 20 | id="feGaussianBlur3775" | ||
1074 | 21 | stdDeviation="3.931875" /> | ||
1075 | 22 | </filter> | ||
1076 | 23 | </defs> | ||
1077 | 24 | <metadata | ||
1078 | 25 | id="metadata3042"> | ||
1079 | 26 | <rdf:RDF> | ||
1080 | 27 | <cc:Work | ||
1081 | 28 | rdf:about=""> | ||
1082 | 29 | <dc:format>image/svg+xml</dc:format> | ||
1083 | 30 | <dc:type | ||
1084 | 31 | rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | ||
1085 | 32 | <dc:title></dc:title> | ||
1086 | 33 | </cc:Work> | ||
1087 | 34 | </rdf:RDF> | ||
1088 | 35 | </metadata> | ||
1089 | 36 | <g | ||
1090 | 37 | transform="translate(-45.0635,-38.936486)" | ||
1091 | 38 | id="g3796"> | ||
1092 | 39 | <rect | ||
1093 | 40 | width="168" | ||
1094 | 41 | height="197" | ||
1095 | 42 | x="108" | ||
1096 | 43 | y="87" | ||
1097 | 44 | id="rect4024" | ||
1098 | 45 | style="fill:#4c77a0;fill-opacity:1;stroke:none" /> | ||
1099 | 46 | <path | ||
1100 | 47 | d="M 102,52.5 C 78.75,55 57.625,71.25 54.5,98 l 0,170.5 c 2.875,25.25 20,43.625 46.5,46 l 168.5,0 c 22.75,-0.625 43.625,-18.125 47.25,-46.5 l 0,-169.375 C 314.25,73.875 292.375,54.5 270,52.5 l -168,0 z m 34,55.75 64.25,0 c 66,0.5 51.15504,62.271 24,68.5 44.5,3.75 50.25,82.5 -23.75,83.25 L 136.25,260 136,108.25 z m 36,27 0,31.75 18,0 c 22.1875,0 23.0625,-31.75 0,-31.75 l -18,0 z m 0,58 0,37.5 24.25,0 c 26.75,0 28,-37.5 0,-37.5 l -24.25,0 z" | ||
1101 | 48 | id="path3978" | ||
1102 | 49 | style="opacity:0.62999998;fill:#000000;fill-opacity:1;stroke:none;filter:url(#filter3773)" /> | ||
1103 | 50 | <path | ||
1104 | 51 | d="M 99,50 C 75.75,52.5 54.625,68.75 51.5,95.5 l 0,170.5 c 2.875,25.25 20,43.625 46.5,46 l 168.5,0 c 22.75,-0.625 43.625,-18.125 47.25,-46.5 l 0,-169.375 C 311.25,71.375 289.375,52 267,50 L 99,50 z m 34,55.75 64.25,0 c 66,0.5 51.15504,62.271 24,68.5 44.5,3.75 50.25,82.5 -23.75,83.25 l -64.25,0 L 133,105.75 z m 36,27 0,31.75 18,0 c 22.1875,0 23.0625,-31.75 0,-31.75 l -18,0 z m 0,58 0,37.5 24.25,0 c 26.75,0 28,-37.5 0,-37.5 l -24.25,0 z" | ||
1105 | 52 | id="path3046" | ||
1106 | 53 | style="fill:#ffffff;fill-opacity:1;stroke:none" /> | ||
1107 | 54 | </g> | ||
1108 | 55 | </svg> |