Merge lp:~joelmontes01/gwibber/Better_Docsting_PEP_257 into lp:gwibber
- Better_Docsting_PEP_257
- Merge into trunk
Proposed by
Joel Montes de Oca
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 1368 | ||||
Proposed branch: | lp:~joelmontes01/gwibber/Better_Docsting_PEP_257 | ||||
Merge into: | lp:gwibber | ||||
Diff against target: |
2059 lines (+835/-478) 6 files modified
gwibber/microblog/plugins/facebook/__init__.py (+82/-47) gwibber/microblog/plugins/flickr/__init__.py (+37/-21) gwibber/microblog/plugins/foursquare/__init__.py (+51/-29) gwibber/microblog/plugins/identica/__init__.py (+212/-121) gwibber/microblog/plugins/statusnet/__init__.py (+215/-124) gwibber/microblog/plugins/twitter/__init__.py (+238/-136) |
||||
To merge this branch: | bzr merge lp:~joelmontes01/gwibber/Better_Docsting_PEP_257 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ken VanDine | Approve | ||
Review via email: mp+109926@code.launchpad.net |
Commit message
Description of the change
Submitting my edits of the docsctrings in the plugin files. If there's no problems with the edits and it's approved, I'll continue editing the docstrings within the GTK files. Nature of edits: converted current docstrings to Python's PEP 257 styles.
To post a comment you must log in.
Revision history for this message
Joel Montes de Oca (joelmontes01) wrote : | # |
Awesome! I'm glad it helped. :)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'gwibber/microblog/plugins/facebook/__init__.py' |
2 | --- gwibber/microblog/plugins/facebook/__init__.py 2012-05-23 14:02:10 +0000 |
3 | +++ gwibber/microblog/plugins/facebook/__init__.py 2012-06-12 20:30:26 +0000 |
4 | @@ -65,6 +65,7 @@ |
5 | |
6 | First, look for the 'updated_time' key in the data, falling back to |
7 | 'created_time' if the former is missing. |
8 | + |
9 | """ |
10 | # Convert from an ISO 8601 format time string to a Epoch timestamp. |
11 | # Assume standard ISO 8601 'T' separator, no microseconds, and naive |
12 | @@ -75,23 +76,30 @@ |
13 | |
14 | |
15 | class Client: |
16 | - """ Client: The Client class is responsible for querying Facebook and turning the data obtained |
17 | - into data that Gwibber can understand. Facebook uses a version of oauth for security. |
18 | + """Query Facebook and convert data. |
19 | + |
20 | + The Client class is responsible for querying Facebook and turning the data obtained |
21 | + into data that Gwibber can understand. Facebook uses a version of oauth for security. |
22 | Tokens have already been obtained when the account was set up in Gwibber and are used to |
23 | authenticate when getting data. |
24 | + |
25 | """ |
26 | def __init__(self, acct): |
27 | self.account = acct |
28 | self.user_id = acct.get("uid", None) |
29 | |
30 | def _check_error(self, data): |
31 | - """Checks to ensure the data obtained by Facebook is on the correct form |
32 | + """Checks if data is from the correct form. |
33 | + |
34 | + Checks to ensure the data obtained by Facebook is on the correct form. |
35 | If not, an error is logged in gwibber.log |
36 | - Args: |
37 | - data: A data structure obtained from Foursquare |
38 | + |
39 | + Arguments: |
40 | + data -- A data structure obtained from Foursquare |
41 | + |
42 | Returns: |
43 | - True if data is contains 'error' or is not a dict. |
44 | - Otherwise, False |
45 | + True if data is contains an error or is not a dictionary, otherwise, False. |
46 | + |
47 | """ |
48 | if isinstance(data, dict): |
49 | if data.has_key("error"): |
50 | @@ -102,14 +110,17 @@ |
51 | return True |
52 | |
53 | def _get(self, operation, post=False, single=False, **args): |
54 | - """ Establishes a connection with Facebook and gets the data requested |
55 | - Args: |
56 | - operation: The end of the url to look up on Facebook |
57 | - post: True is this is a send, False if a recieve (False by default) |
58 | - single: True if a single checkin is requested, False if multiple (False by default) |
59 | - **args: Args to be added to the url when accessed. |
60 | + """Establishes a connection with Facebook and gets the data requested. |
61 | + |
62 | + Arguments: |
63 | + operation -- The end of the URL to look up on Facebook |
64 | + post -- True is this is a send, False if a receive (False by default) |
65 | + single -- True if a single checkin is requested, False if multiple (False by default) |
66 | + **args -- Arguments to be added to the URL when accessed. |
67 | + |
68 | Returns: |
69 | - A list of facebook objects |
70 | + A list of Facebook objects. |
71 | + |
72 | """ |
73 | if not self.user_id or "access_token" not in self.account: |
74 | logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Authentication failed"), "Auth needs updating") |
75 | @@ -143,11 +154,14 @@ |
76 | return data |
77 | |
78 | def _sender(self, data): |
79 | - """ Parses the sender of the facebook object |
80 | - Args: |
81 | - data: A facebook object |
82 | + """Parses the sender of the Facebook object. |
83 | + |
84 | + Arguments: |
85 | + data -- A Facebook object |
86 | + |
87 | Returns: |
88 | - A sender object in a format compatible with gwibber's database |
89 | + A sender object in a format compatible with Gwibber's database. |
90 | + |
91 | """ |
92 | sender = { |
93 | "name": data["name"], |
94 | @@ -159,11 +173,14 @@ |
95 | return sender |
96 | |
97 | def _message(self, data): |
98 | - """ Parses a facebook object |
99 | - Args: |
100 | - data: A facebook object |
101 | + """Parses a Facebook object. |
102 | + |
103 | + Arguments: |
104 | + data -- A Facebook object |
105 | + |
106 | Returns: |
107 | - A facebook object in a format compatible with gwibber's database |
108 | + A Facebook object in a format compatible with Gwibber's database. |
109 | + |
110 | """ |
111 | if type(data) != dict: |
112 | logger.error("Cannot parse message data: %s", str(data)) |
113 | @@ -302,11 +319,14 @@ |
114 | return getattr(self, opname)(**args) |
115 | |
116 | def receive(self, since=None): |
117 | - """ Gets a list of facebook objects and add them to the database. |
118 | - Args: |
119 | - since: the time to get facebook objects from |
120 | + """Gets a list of Facebook objects and add them to the database. |
121 | + |
122 | + Arguments: |
123 | + since -- The time to get Facebook objects from |
124 | + |
125 | Returns: |
126 | - A list of gwibber compatible objects which have been parsed by the parse function |
127 | + A list of Gwibber compatible objects which have been parsed by the parse function. |
128 | + |
129 | """ |
130 | if since is None: |
131 | since = (datetime.now() - timedelta(hours=240.0)).isoformat() |
132 | @@ -327,11 +347,14 @@ |
133 | else: return |
134 | |
135 | def delete(self, message): |
136 | - """ Deletes a specified message from facebook |
137 | - Args: |
138 | - message: a gwibber compatible message object (from gwibber's database) |
139 | + """Deletes a specified message from Facebook. |
140 | + |
141 | + Arguments: |
142 | + message -- A Gwibber compatible message object (from Gwibber's database) |
143 | + |
144 | Returns: |
145 | - Nothing |
146 | + Nothing |
147 | + |
148 | """ |
149 | result = self._get("stream.remove", post_id=message["mid"]) |
150 | if not result: |
151 | @@ -340,11 +363,14 @@ |
152 | return [] |
153 | |
154 | def like(self, message): |
155 | - """ Likes a specified message on facebook |
156 | - Args: |
157 | - message: a gwibber compatible message object (from gwibber's database) |
158 | + """Likes a specified message on Facebook. |
159 | + |
160 | + Arguments: |
161 | + message -- a Gwibber compatible message object (from Gwibber's database) |
162 | + |
163 | Returns: |
164 | - The liked message |
165 | + The liked message |
166 | + |
167 | """ |
168 | result = self._get(message["mid"] + "/likes", post=True) |
169 | if not result: |
170 | @@ -354,11 +380,14 @@ |
171 | return data |
172 | |
173 | def unlike(self, message): |
174 | - """ Unlikes a specified message on facebook |
175 | - Args: |
176 | - message: a gwibber compatible message object (from gwibber's database) |
177 | + """Unlikes a specified message on Facebook. |
178 | + |
179 | + Arguments: |
180 | + message -- A Gwibber compatible message object (from Gwibber's database) |
181 | + |
182 | Returns: |
183 | - The unliked message |
184 | + The unliked message |
185 | + |
186 | """ |
187 | result = self._get(message["mid"] + "/likes", post=True, method="delete") |
188 | if not result: |
189 | @@ -368,11 +397,14 @@ |
190 | return data |
191 | |
192 | def send(self, message): |
193 | - """ Sends a message to facebook |
194 | - Args: |
195 | - message: The text of the message |
196 | + """Sends a message to Facebook. |
197 | + |
198 | + Arguments: |
199 | + message -- The text of the message |
200 | + |
201 | Returns: |
202 | - Nothing |
203 | + Nothing |
204 | + |
205 | """ |
206 | result = self._get("me/feed", message=message, status_includes_verb=True, post=True) |
207 | if not result: |
208 | @@ -381,12 +413,15 @@ |
209 | return [] |
210 | |
211 | def send_thread(self, message, target): |
212 | - """ Sends a message to facebook as a reply to another message |
213 | - Args: |
214 | - message: The text of the message |
215 | - target: The person the message is directed at (as a gwibber compatible object) |
216 | + """Sends a message to Facebook as a reply to another message. |
217 | + |
218 | + Arguments: |
219 | + message -- The text of the message |
220 | + target -- The person the message is directed at (as a Gwibber compatible object) |
221 | + |
222 | Returns: |
223 | - Nothing |
224 | + Nothing |
225 | + |
226 | """ |
227 | result = self._get(target["mid"] + "/comments", message=message, post=True) |
228 | if not result: |
229 | |
230 | === modified file 'gwibber/microblog/plugins/flickr/__init__.py' |
231 | --- gwibber/microblog/plugins/flickr/__init__.py 2012-05-23 14:02:10 +0000 |
232 | +++ gwibber/microblog/plugins/flickr/__init__.py 2012-06-12 20:30:26 +0000 |
233 | @@ -37,18 +37,24 @@ |
234 | IMAGE_PAGE_URL = "http://www.flickr.com/photos/%s/%s" |
235 | |
236 | class Client: |
237 | - """ Client: The Client class is responsible for querying Flickr and turning the data obtained |
238 | - into data that Gwibber can understand. |
239 | + """Query Flickr, retrieve and convert data. |
240 | + |
241 | + The Client class is responsible for querying Flickr and |
242 | + turning the data obtained into data that Gwibber can understand. |
243 | + |
244 | """ |
245 | def __init__(self, acct): |
246 | self.account = acct |
247 | |
248 | def _message(self, data): |
249 | - """ Parses messages into gwibber compatible forms. |
250 | - Args: |
251 | - data: A data object obtained from Twitter containing a complete tweet |
252 | + """Parses messages into Gwibber compatible forms. |
253 | + |
254 | + Arguments: |
255 | + data -- A data object obtained from Flickr containing a complete entry |
256 | + |
257 | Returns: |
258 | - m: A data object compatible with inserting into the Gwibber database for that tweet |
259 | + m -- A data object compatible with inserting into the Gwibber database for that entry |
260 | + |
261 | """ |
262 | m = {} |
263 | m["mid"] = str(data["id"]) |
264 | @@ -80,14 +86,17 @@ |
265 | return m |
266 | |
267 | def _get(self, method, parse="message", post=False, **args): |
268 | - """ Establishes a connection with Flickr and gets the data requested. |
269 | - Args: |
270 | - method: The method to look up on Flickr |
271 | - parse: The function to use to parse the data returned (message by default) |
272 | - post: True is this is a send, False if a recieve (False by default) |
273 | - **args: Args to be added to the url when accessed. |
274 | + """Establishes a connection with Flickr and gets the data requested. |
275 | + |
276 | + Arguments: |
277 | + method -- The method to look up on Flickr |
278 | + parse -- The function to use to parse the data returned (message by default) |
279 | + post -- True is this is a send, False if a receive (False by default) |
280 | + **args -- Argument to be added to the URL when accessed |
281 | + |
282 | Returns: |
283 | - A list of gwibber compatible objects which have been parsed by the parse function |
284 | + A list of Gwibber compatible objects which have been parsed by the parse function. |
285 | + |
286 | """ |
287 | args.update({"api_key": API_KEY, "method": method}) |
288 | data = network.Download(REST_SERVER, args, post).get_json() |
289 | @@ -97,11 +106,14 @@ |
290 | else: return data |
291 | |
292 | def _getNSID(self): |
293 | - """ Gets users own Flickr id |
294 | - Args: |
295 | - None |
296 | + """Gets user's own Flickr ID. |
297 | + |
298 | + Arguments: |
299 | + None |
300 | + |
301 | Returns: |
302 | - A flickr user id |
303 | + The user's Flickr id. |
304 | + |
305 | """ |
306 | data = self._get("flickr.people.findByUsername", |
307 | parse=None, nojsoncallback="1", format="json", |
308 | @@ -116,11 +128,15 @@ |
309 | return getattr(self, opname)(**args) |
310 | |
311 | def images(self): |
312 | - """ Gets a stream of images from Flickr |
313 | - Args: |
314 | - None |
315 | + """Gets a stream of images from Flickr. |
316 | + |
317 | + Arguments: |
318 | + None |
319 | + |
320 | Returns: |
321 | - A list of gwibber compatible objects which have been parsed by the parse function |
322 | + A list of Gwibber compatible objects which have been |
323 | + parsed by the parse function. |
324 | + |
325 | """ |
326 | user_id=self._getNSID() |
327 | if user_id: |
328 | |
329 | === modified file 'gwibber/microblog/plugins/foursquare/__init__.py' |
330 | --- gwibber/microblog/plugins/foursquare/__init__.py 2012-04-10 17:42:04 +0000 |
331 | +++ gwibber/microblog/plugins/foursquare/__init__.py 2012-06-12 20:30:26 +0000 |
332 | @@ -34,10 +34,14 @@ |
333 | URL_PREFIX = "https://api.foursquare.com/v2" |
334 | |
335 | class Client: |
336 | - """ Client: The Client class is responsible for querying Foursquare and turning the data obtained |
337 | - into data that Gwibber can understand. Foursquare uses a version of oauth for security. |
338 | + """Query Foursquare and converts data. |
339 | + |
340 | + The Client class is responsible for querying Foursquare and turning the data obtained |
341 | + into data that Gwibber can understand. Foursquare uses a version of OAuth for security. |
342 | + |
343 | Tokens have already been obtained when the account was set up in Gwibber and are used to |
344 | authenticate when getting data. |
345 | + |
346 | """ |
347 | def __init__(self, acct): |
348 | self.service = util.getbus("Service") |
349 | @@ -50,11 +54,14 @@ |
350 | self.token = acct["access_token"] |
351 | |
352 | def _message(self, data): |
353 | - """ Parses messages into gwibber compatible forms |
354 | - Args: |
355 | - data: A data object obtained from Foursquare containing a complete checkin |
356 | + """Parses messages into Gwibber compatible forms. |
357 | + |
358 | + Arguments: |
359 | + data -- A data object obtained from Foursquare containing a complete checkin |
360 | + |
361 | Returns: |
362 | - m: A data object compatible with inserting into the Gwibber database for that checkin |
363 | + m -- A data object compatible with inserting into the Gwibber database for that checkin |
364 | + |
365 | """ |
366 | m = {}; |
367 | m["mid"] = str(data["id"]) |
368 | @@ -170,13 +177,17 @@ |
369 | return m |
370 | |
371 | def _check_error(self, data): |
372 | - """Checks to ensure the data obtained by Foursquare is on the correct form |
373 | - If not, an error is logged in gwibber.log |
374 | - Args: |
375 | - data: A data structure obtained from Foursquare |
376 | + """Checks to ensure the data obtained by Foursquare is in the correct form. |
377 | + |
378 | + If it's not in the correct form, an error is logged in gwibber.log |
379 | + |
380 | + Arguments: |
381 | + data -- A data structure obtained from Foursquare |
382 | + |
383 | Returns: |
384 | - True if data is valid (is a dict and contains a 'recent' parameter. |
385 | - Otherwise, False |
386 | + True if data is valid (is a dictionary and contains a 'recent' parameter). |
387 | + If the data is not valid, then return False. |
388 | + |
389 | """ |
390 | if isinstance(data, dict) and "recent" in data: |
391 | return True |
392 | @@ -185,11 +196,14 @@ |
393 | return False |
394 | |
395 | def _get_comments(self, checkin_id): |
396 | - """ Gets comments on a particular checkin id. |
397 | - Args: |
398 | - checkin_id: The checkin id of the checkin |
399 | + """Gets comments on a particular check in ID. |
400 | + |
401 | + Arguments: |
402 | + checkin_id -- The checkin id of the checkin |
403 | + |
404 | Returns: |
405 | - A comment object |
406 | + A comment object |
407 | + |
408 | """ |
409 | url = "/".join((URL_PREFIX, "checkins", checkin_id)) |
410 | url = url + "?oauth_token=" + self.token |
411 | @@ -197,15 +211,18 @@ |
412 | return data["checkin"]["comments"]["items"] |
413 | |
414 | def _get(self, path, parse="message", post=False, single=False, **args): |
415 | - """ Establishes a connection with Foursquare and gets the data requested |
416 | - Args: |
417 | - path: The end of the url to look up on Foursquare |
418 | - parse: The function to use to parse the data returned (message by default) |
419 | - post: True is this is a send, False if a recieve (False by default) |
420 | - single: True if a single checkin is requested, False if multiple (False by default) |
421 | - **args: Args to be added to the url when accessed. |
422 | + """Establishes a connection with Foursquare and gets the data requested. |
423 | + |
424 | + Arguments: |
425 | + path -- The end of the URL to look up on Foursquare |
426 | + parse -- The function to use to parse the data returned (message by default) |
427 | + post -- True if using POST, for example the send operation. False if using GET, most operations other than send. (False by default) |
428 | + single -- True if a single checkin is requested, False if multiple (False by default) |
429 | + **args -- Arguments to be added to the URL when accessed |
430 | + |
431 | Returns: |
432 | - A list of gwibber compatible objects which have been parsed by the parse function |
433 | + A list of Gwibber compatible objects which have been parsed by the parse function. |
434 | + |
435 | """ |
436 | url = "/".join((URL_PREFIX, path)) |
437 | |
438 | @@ -245,11 +262,16 @@ |
439 | return getattr(self, opname)(**args) |
440 | |
441 | def receive(self): |
442 | - """ Gets a list of each friend's most recent checkins and add them to |
443 | - the database. |
444 | - Args: |
445 | - None |
446 | + """Gets a list of each friend's most recent check-ins. |
447 | + |
448 | + The list of each friend's recent check-ins is then |
449 | + saved to the database. |
450 | + |
451 | + Arguments: |
452 | + None |
453 | + |
454 | Returns: |
455 | - A list of gwibber compatible objects which have been parsed by the parse function |
456 | + A list of Gwibber compatible objects which have been parsed by the parse function. |
457 | + |
458 | """ |
459 | return self._get("checkins/recent") |
460 | |
461 | === modified file 'gwibber/microblog/plugins/identica/__init__.py' |
462 | --- gwibber/microblog/plugins/identica/__init__.py 2012-05-23 14:02:10 +0000 |
463 | +++ gwibber/microblog/plugins/identica/__init__.py 2012-06-12 20:30:26 +0000 |
464 | @@ -60,10 +60,14 @@ |
465 | URL_PREFIX = "https://identi.ca" |
466 | |
467 | class Client: |
468 | - """ Client: The Client class is responsible for querying Identica and turning the data obtained |
469 | - into data that Gwibber can understand. Identica uses a version of oauth for security. |
470 | + """Query Identica and convert data. |
471 | + |
472 | + The Client class is responsible for querying Identica and turning the data obtained |
473 | + into data that Gwibber can understand. Identica uses a version of OAuth for security. |
474 | + |
475 | Tokens have already been obtained when the account was set up in Gwibber and are used to |
476 | authenticate when getting data. |
477 | + |
478 | """ |
479 | def __init__(self, acct): |
480 | self.url_prefix = "https://identi.ca" |
481 | @@ -72,12 +76,17 @@ |
482 | self.account = acct |
483 | |
484 | def _common(self, data): |
485 | - """ Parses messages into gwibber compatible forms. This function is common to all tweet types |
486 | - and includes parsing of user mentions, hashtags, urls, images and videos |
487 | - Args: |
488 | - data: A data object obtained from Identica containing a complete update |
489 | + """Parses messages into Gwibber compatible forms. |
490 | + |
491 | + This function is common to all tweet types and includes |
492 | + parsing of user mentions, hashtags, urls, images and videos. |
493 | + |
494 | + Arguments: |
495 | + data -- A data object obtained from Identica containing a complete update |
496 | + |
497 | Returns: |
498 | - m: A data object compatible with inserting into the Gwibber database for that update |
499 | + m -- A data object compatible with inserting into the Gwibber database for that update |
500 | + |
501 | """ |
502 | m = {} |
503 | try: |
504 | @@ -118,11 +127,14 @@ |
505 | return m |
506 | |
507 | def _user(self, user): |
508 | - """ Parses the user portion of an update |
509 | - Args: |
510 | - user: A user object from an update |
511 | + """Parses the user portion of an update. |
512 | + |
513 | + Arguments: |
514 | + user -- A user object from an update |
515 | + |
516 | Returns: |
517 | - A user object in a format compatible with gwibber's database |
518 | + A user object in a format compatible with Gwibber's database. |
519 | + |
520 | """ |
521 | return { |
522 | "name": user.get("name", None), |
523 | @@ -142,13 +154,19 @@ |
524 | } |
525 | |
526 | def _message(self, data): |
527 | - """ Parses messages into gwibber compatible forms. This is the initial function for |
528 | - update parsing and parses retweeted status (the shared-by portion) |
529 | - and reply details (the in-reply-to portion). It sends the rest to _common() for further parsing |
530 | - Args: |
531 | - data: A data object obtained from Identica containing a complete update |
532 | + """Parses messages into Gwibber compatible forms. |
533 | + |
534 | + This is the initial function for update parsing and parses |
535 | + retweeted status (the shared-by portion) and reply details |
536 | + (the in-reply-to portion). It sends the rest to _common() |
537 | + for further parsing. |
538 | + |
539 | + Arguments: |
540 | + data -- A data object obtained from Identica containing a complete update |
541 | + |
542 | Returns: |
543 | - m: A data object compatible with inserting into the Gwibber database for that update |
544 | + m -- A data object compatible with inserting into the Gwibber database for that update |
545 | + |
546 | """ |
547 | if type(data) != dict: |
548 | logger.error("Cannot parse message data: %s", str(data)) |
549 | @@ -186,13 +204,21 @@ |
550 | return m |
551 | |
552 | def _private(self, data): |
553 | - """ Sets the message type and privacy if the message should be in the private stream. |
554 | - Also parses the recipient as both sent & recieved messages can be in the private stream. |
555 | - It sends the rest to _message() for further parsing |
556 | - Args: |
557 | - data: A data object obtained from Identica containing a complete update |
558 | + """Sets the message type and privacy. |
559 | + |
560 | + Sets the type and privacy of a message if the message |
561 | + should be in the private stream. |
562 | + |
563 | + Also parses the recipient as both sent & recieved messages |
564 | + can be in the private stream. It sends the rest to _message() |
565 | + for further parsing. |
566 | + |
567 | + Arguments: |
568 | + data -- A data object obtained from Identica containing a complete update |
569 | + |
570 | Returns: |
571 | - m: A data object compatible with inserting into the Gwibber database for that update |
572 | + m -- A data object compatible with inserting into the Gwibber database for that update |
573 | + |
574 | """ |
575 | m = self._message(data) |
576 | m["private"] = True |
577 | @@ -208,12 +234,17 @@ |
578 | return m |
579 | |
580 | def _result(self, data): |
581 | - """ Called when a search is done in gwibber. Parses the sender and sends the rest to _common() |
582 | - for further parsing |
583 | - Args: |
584 | - data: A data object obtained from Identica containing a complete update |
585 | + """Called when a search is done in Gwibber. |
586 | + |
587 | + Parses the sender and sends the rest to _common() |
588 | + for further parsing. |
589 | + |
590 | + Arguments: |
591 | + data -- A data object obtained from Identica containing a complete update |
592 | + |
593 | Returns: |
594 | - m: A data object compatible with inserting into the Gwibber database for that update |
595 | + m -- A data object compatible with inserting into the Gwibber database for that update |
596 | + |
597 | """ |
598 | m = self._common(data) |
599 | |
600 | @@ -231,11 +262,14 @@ |
601 | return m |
602 | |
603 | def _profile(self, data): |
604 | - """ Called when a user is clicked on. |
605 | - Args: |
606 | - data: A data object obtained from Identica containing a complete user |
607 | + """Called when a user is clicked on. |
608 | + |
609 | + Arguments: |
610 | + data -- A data object obtained from Identica containing a complete user |
611 | + |
612 | Returns: |
613 | - A data object compatible with inserting into the Gwibber database for that user |
614 | + A data object compatible with inserting into the Gwibber database for that user |
615 | + |
616 | """ |
617 | return { |
618 | "name": data.get("name", data["screen_name"]), |
619 | @@ -262,15 +296,20 @@ |
620 | } |
621 | |
622 | def _get(self, path, parse="message", post=False, single=False, **args): |
623 | - """ Establishes a connection with Identica and gets the data requested. Requires authentication. |
624 | - Args: |
625 | - path: The end of the url to look up on Identica |
626 | - parse: The function to use to parse the data returned (message by default) |
627 | - post: True is this is a send, False if a recieve (False by default) |
628 | - single: True if a single checkin is requested, False if multiple (False by default) |
629 | - **args: Args to be added to the url when accessed. |
630 | + """Establishes a connection with Identica and gets the data requested. |
631 | + |
632 | + Requires authentication. |
633 | + |
634 | + Arguments: |
635 | + path -- The end of the url to look up on Identica |
636 | + parse -- The function to use to parse the data returned (message by default) |
637 | + post -- True if using POST, for example the send operation. False if using GET, most operations other than send. (False by default) |
638 | + single -- True if a single checkin is requested, False if multiple (False by default) |
639 | + **args -- Args to be added to the url when accessed. |
640 | + |
641 | Returns: |
642 | - A list of gwibber compatible objects which have been parsed by the parse function |
643 | + A list of Gwibber compatible objects which have been parsed by the parse function. |
644 | + |
645 | """ |
646 | if not self.account.has_key("access_token") and not self.account.has_key("secret_token"): |
647 | logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], _("Account needs to be re-authorized")) |
648 | @@ -321,12 +360,16 @@ |
649 | return [self._result(m) for m in data] |
650 | |
651 | def _search(self, **args): |
652 | - """ Establishes a connection with Identica and gets the results of a search. |
653 | - Does not require authentication |
654 | - Args: |
655 | - **args: The search terms |
656 | + """Establishes a connection with Identica and gets the results of a search. |
657 | + |
658 | + Does not require authentication. |
659 | + |
660 | + Arguments: |
661 | + **args -- The search terms |
662 | + |
663 | Returns: |
664 | - A list of gwibber compatible objects which have been parsed by _result() |
665 | + A list of Gwibber compatible objects which have been parsed by _result(). |
666 | + |
667 | """ |
668 | data = network.Download("%s/api/search.json" % self.url_prefix, util.compact(args)) |
669 | data = data.get_json() |
670 | @@ -341,167 +384,215 @@ |
671 | return getattr(self, opname)(**args) |
672 | |
673 | def receive(self, count=util.COUNT, since=None): |
674 | - """ Gets the latest updates and adds them to the database. |
675 | - Args: |
676 | - count = number of updates to get |
677 | - since = time to get updates since |
678 | + """Gets the latest updates and adds them to the database. |
679 | + |
680 | + Arguments: |
681 | + count -- Number of updates to get |
682 | + since -- Time to get updates since |
683 | + |
684 | Returns: |
685 | - A list of gwibber compatible objects which have been parsed by _message() |
686 | + A list of Gwibber compatible objects which have been parsed by _message(). |
687 | + |
688 | """ |
689 | return self._get("statuses/friends_timeline.json", count=count, since_id=since) |
690 | |
691 | def responses(self, count=util.COUNT, since=None): |
692 | - """ Gets the latest replies and adds them to the database. |
693 | - Args: |
694 | - count = number of updates to get |
695 | - since = time to get updates since |
696 | + """Gets the latest replies and adds them to the database. |
697 | + |
698 | + Arguments: |
699 | + count -- number of updates to get |
700 | + since -- time to get updates since |
701 | + |
702 | Returns: |
703 | - A list of gwibber compatible objects which have been parsed by _responses() |
704 | + A list of Gwibber compatible objects which have been parsed by _responses(). |
705 | + |
706 | """ |
707 | return self._get("statuses/mentions.json", count=count, since_id=since) |
708 | |
709 | def private(self, count=util.COUNT, since=None): |
710 | - """ Gets the latest direct messages sent and recieved and adds them to the database. |
711 | + """Gets the latest direct messages sent and recieved and adds them to the database. |
712 | + |
713 | Args: |
714 | - count = number of updates to get |
715 | - since = time to get updates since |
716 | + count -- Number of updates to get |
717 | + since -- Time to get updates since |
718 | + |
719 | Returns: |
720 | - A list of gwibber compatible objects which have been parsed by _private() |
721 | + A list of Gwibber compatible objects which have been parsed by _private(). |
722 | + |
723 | """ |
724 | private = self._get("direct_messages.json", "private", count=count, since_id=since) or [] |
725 | private_sent = self._get("direct_messages/sent.json", "private", count=count, since_id=since) or [] |
726 | return private + private_sent |
727 | |
728 | def public(self, count=util.COUNT, since=None): |
729 | - """ Gets the latest updates from the public timeline and adds them to the database. |
730 | - Args: |
731 | - count = number of updates to get |
732 | - since = time to get updates since |
733 | + """Gets the latest updates from the public timeline and adds them to the database. |
734 | + |
735 | + Arguments: |
736 | + count -- Number of updates to get |
737 | + since -- Time to get updates since |
738 | + |
739 | Returns: |
740 | - A list of gwibber compatible objects which have been parsed by _message() |
741 | + A list of Gwibber compatible objects which have been parsed by _message(). |
742 | + |
743 | """ |
744 | return self._get("statuses/public_timeline.json") |
745 | |
746 | def search(self, query, count=util.COUNT, since=None): |
747 | - """ Gets the latest results from a search and adds them to the database. |
748 | - Args: |
749 | - query = the search query |
750 | - count = number of updates to get |
751 | - since = time to get updates since |
752 | + """Gets the latest results from a search and adds them to the database. |
753 | + |
754 | + Arguments: |
755 | + query -- The search query |
756 | + count -- Number of updates to get |
757 | + since -- Time to get updates since |
758 | + |
759 | Returns: |
760 | - A list of gwibber compatible objects which have been parsed by _search() |
761 | + A list of Gwibber compatible objects which have been parsed by _search(). |
762 | + |
763 | """ |
764 | return self._search(q=query, rpp=count, since_id=since) |
765 | |
766 | def tag(self, query, count=util.COUNT, since=None): |
767 | - """ Gets the latest results from a hashtag search and adds them to the database. |
768 | - Args: |
769 | - query = the search query (hashtag without the #) |
770 | - count = number of updates to get |
771 | - since = time to get updates since |
772 | + """Gets the latest results from a hashtag search and adds them to the database. |
773 | + |
774 | + Arguments: |
775 | + query -- The search query (hashtag without the #) |
776 | + count -- Number of updates to get |
777 | + since -- Time to get updates since |
778 | + |
779 | Returns: |
780 | - A list of gwibber compatible objects which have been parsed by _search() |
781 | + A list of Gwibber compatible objects which have been parsed by _search(). |
782 | + |
783 | """ |
784 | return self._search(q="#%s" % query, count=count, since_id=since) |
785 | |
786 | def delete(self, message): |
787 | - """ Deletes a specified tweet from Identica |
788 | - Args: |
789 | - message: a gwibber compatible message object (from gwibber's database) |
790 | + """Deletes a specified tweet from Identica. |
791 | + |
792 | + Arguments: |
793 | + message -- A Gwibber compatible message object (from gwibber's database) |
794 | + |
795 | Returns: |
796 | - Nothing |
797 | + Nothing |
798 | + |
799 | """ |
800 | self._get("statuses/destroy/%s.json" % message["mid"], None, post=True, do=1) |
801 | return [] |
802 | |
803 | def like(self, message): |
804 | - """ Favourites a specified tweet on Identica |
805 | - Args: |
806 | - message: a gwibber compatible message object (from gwibber's database) |
807 | + """Favourites a specified tweet on Identica. |
808 | + |
809 | + Arguments: |
810 | + message -- A Gwibber compatible message object (from Gwibber's database) |
811 | + |
812 | Returns: |
813 | - Nothing |
814 | + Nothing |
815 | + |
816 | """ |
817 | self._get("favorites/create/%s.json" % message["mid"], None, post=True, do=1) |
818 | return [] |
819 | |
820 | def send(self, message): |
821 | - """ Sends an update to Identica |
822 | - Args: |
823 | - message: The update's text |
824 | + """Sends an update to Identica. |
825 | + |
826 | + Arguments: |
827 | + message -- The update's text |
828 | + |
829 | Returns: |
830 | - Nothing |
831 | + Nothing |
832 | + |
833 | """ |
834 | return self._get("statuses/update.json", post=True, single=True, |
835 | status=message, source="Gwibber") |
836 | |
837 | def send_private(self, message, private): |
838 | - """ Sends a direct message to Identica |
839 | - Args: |
840 | - message: The update's text |
841 | - private: A gwibber compatible user object (from gwibber's database) |
842 | + """Sends a direct message to Identica. |
843 | + |
844 | + Arguments: |
845 | + message -- The update's text |
846 | + private -- A Gwibber compatible user object (from Gwibber's database) |
847 | + |
848 | Returns: |
849 | - Nothing |
850 | + Nothing |
851 | + |
852 | """ |
853 | return self._get("direct_messages/new.json", "private", post=True, single=True, |
854 | text=message, screen_name=private["sender"]["nick"]) |
855 | |
856 | def send_thread(self, message, target): |
857 | - """ Sends a reply to a user on Identica |
858 | - Args: |
859 | - message: The update's text |
860 | - target: A gwibber compatible user object (from gwibber's database) |
861 | + """Sends a reply to a user on Identica. |
862 | + |
863 | + Arguments: |
864 | + message -- The update's text |
865 | + target -- A Gwibber compatible user object (from Gwibber's database) |
866 | + |
867 | Returns: |
868 | - Nothing |
869 | + Nothing |
870 | + |
871 | """ |
872 | return self._get("statuses/update.json", post=True, single=True, |
873 | status=message, source="Gwibber", in_reply_to_status_id=target["mid"]) |
874 | |
875 | def retweet(self, message): |
876 | - """ Shares an update |
877 | - Args: |
878 | - message: A gwibber compatible message object (from gwibber's database) |
879 | + """Shares an update. |
880 | + |
881 | + Arguments: |
882 | + message -- A Gwibber compatible message object (from Gwibber's database) |
883 | + |
884 | Returns: |
885 | - Nothing |
886 | + Nothing |
887 | + |
888 | """ |
889 | return self._get("statuses/retweet/%s.json" % message["mid"], None, post=True, do=1, source="Gwibber") |
890 | |
891 | def follow(self, screen_name): |
892 | - """ Follows a user |
893 | - Args: |
894 | - screen_name: The screen name of the user to be followed |
895 | + """Follows a user. |
896 | + |
897 | + Arguments: |
898 | + screen_name -- The screen name of the user to be followed |
899 | + |
900 | Returns: |
901 | - Nothing |
902 | + Nothing |
903 | + |
904 | """ |
905 | return self._get("friendships/create.json", screen_name=screen_name, post=True, parse="follow", source="Gwibber") |
906 | |
907 | def unfollow(self, screen_name): |
908 | - """ Unfollows a user |
909 | - Args: |
910 | - screen_name: The screen name of the user to be unfollowed |
911 | + """Unfollows a user. |
912 | + |
913 | + Arguments: |
914 | + screen_name -- The screen name of the user to be unfollowed |
915 | + |
916 | Returns: |
917 | - Nothing |
918 | + Nothing |
919 | + |
920 | """ |
921 | return self._get("friendships/destroy.json", screen_name=screen_name, post=True, parse="unfollow", source="Gwibber") |
922 | |
923 | def profile(self, id=None, count=None, since=None): |
924 | - """ Gets a user's profile |
925 | - Args: |
926 | - id: The user's screen name |
927 | - count: Number of updates to get |
928 | - since: Time to get updates since |
929 | + """Gets a user's profile. |
930 | + |
931 | + Arguments: |
932 | + id -- The user's screen name |
933 | + count -- Number of updates to get |
934 | + since -- Time to get updates since |
935 | + |
936 | Returns: |
937 | - A list of gwibber compatible objects which have been parsed by _profile() |
938 | + A list of Gwibber compatible objects which have been parsed by _profile(). |
939 | + |
940 | """ |
941 | return self._get("users/show.json", screen_name=id, count=count, since_id=since, parse="profile", source="Gwibber") |
942 | |
943 | def user_messages(self, id=None, count=util.COUNT, since=None): |
944 | - """ Gets a user's profile & timeline |
945 | + """Gets a user's profile & timeline. |
946 | + |
947 | Args: |
948 | - id: The user's screen name |
949 | - count: Number of updates to get |
950 | - since: Time to get updates since |
951 | + id -- The user's screen name |
952 | + count -- Number of updates to get |
953 | + since -- Time to get updates since |
954 | + |
955 | Returns: |
956 | - A list of gwibber compatible objects which have been parsed by _profile() |
957 | + A list of Gwibber compatible objects which have been parsed by _profile(). |
958 | + |
959 | """ |
960 | profiles = [self.profile(id)] or [] |
961 | messages = self._get("statuses/user_timeline.json", id=id, count=count, since_id=since, source="Gwibber") or [] |
962 | |
963 | === modified file 'gwibber/microblog/plugins/statusnet/__init__.py' |
964 | --- gwibber/microblog/plugins/statusnet/__init__.py 2012-05-23 14:02:10 +0000 |
965 | +++ gwibber/microblog/plugins/statusnet/__init__.py 2012-06-12 20:30:26 +0000 |
966 | @@ -12,7 +12,7 @@ |
967 | PROTOCOL_INFO = { |
968 | "name": "StatusNet", |
969 | "version": 1.1, |
970 | - |
971 | + |
972 | "config": [ |
973 | "private:secret_token", |
974 | "access_token", |
975 | @@ -56,10 +56,14 @@ |
976 | } |
977 | |
978 | class Client: |
979 | - """ Client: The Client class is responsible for querying the StatusNet server and turning the data obtained |
980 | - into data that Gwibber can understand. The StatusNet server uses a version of oauth for security. |
981 | - Tokens have already been obtained when the account was set up in Gwibber and are used to |
982 | + """Query the StatusNet server and convert the data. |
983 | + |
984 | + The Client class is responsible for querying the StatusNet server and turning the data obtained |
985 | + into data that Gwibber can understand. The StatusNet server uses a version of OAuth for security. |
986 | + |
987 | + Tokens have already been obtained when the account was set up in Gwibber and are used to |
988 | authenticate when getting data. |
989 | + |
990 | """ |
991 | def __init__(self, acct): |
992 | if acct.has_key("url_prefix"): |
993 | @@ -71,12 +75,18 @@ |
994 | self.account = acct |
995 | |
996 | def _common(self, data): |
997 | - """ Parses messages into gwibber compatible forms. This function is common to all update types |
998 | - and includes parsing of user mentions, hashtags, urls, images and videos |
999 | - Args: |
1000 | - data: A data object obtained from the StatusNet server containing a complete update |
1001 | - Returns: |
1002 | - m: A data object compatible with inserting into the Gwibber database for that update |
1003 | + """Parses messages into Gwibber compatible forms. |
1004 | + |
1005 | + This function is common to all update types |
1006 | + and includes parsing of user mentions, hashtags, |
1007 | + urls, images and videos. |
1008 | + |
1009 | + Arguments: |
1010 | + data -- A data object obtained from the StatusNet server containing a complete update |
1011 | + |
1012 | + Returns: |
1013 | + m -- A data object compatible with inserting into the Gwibber database for that update |
1014 | + |
1015 | """ |
1016 | m = {} |
1017 | try: |
1018 | @@ -107,7 +117,7 @@ |
1019 | images.append({"src": a["url"], "url": a["url"]}) |
1020 | |
1021 | images.extend(util.imgpreview(m["text"])) |
1022 | - |
1023 | + |
1024 | if images: |
1025 | m["images"] = images |
1026 | m["type"] = "photo" |
1027 | @@ -117,11 +127,14 @@ |
1028 | return m |
1029 | |
1030 | def _user(self, user): |
1031 | - """ Parses the user portion of an update |
1032 | - Args: |
1033 | - user: A user object from an update |
1034 | + """Parses the user portion of an update. |
1035 | + |
1036 | + Arguments: |
1037 | + user -- A user object from an update |
1038 | + |
1039 | Returns: |
1040 | - A user object in a format compatible with gwibber's database |
1041 | + A user object in a format compatible with Gwibber's database |
1042 | + |
1043 | """ |
1044 | return { |
1045 | "name": user.get("name", None), |
1046 | @@ -141,13 +154,19 @@ |
1047 | } |
1048 | |
1049 | def _message(self, data): |
1050 | - """ Parses messages into gwibber compatible forms. This is the initial function for |
1051 | - tweet parsing and parses shared status, source (the program the update was sent from) |
1052 | - and reply details (the in-reply-to portion). It sends the rest to _common() for further parsing |
1053 | - Args: |
1054 | - data: A data object obtained from the StatusNet server containing a complete update |
1055 | - Returns: |
1056 | - m: A data object compatible with inserting into the Gwibber database for that tweet |
1057 | + """Parses messages into Gwibber compatible forms. |
1058 | + |
1059 | + This is the initial function for tweet parsing and parses |
1060 | + shared status, source (the program the update was sent from) |
1061 | + and reply details (the in-reply-to portion). It sends the rest |
1062 | + to _common() for further parsing. |
1063 | + |
1064 | + Arguments: |
1065 | + data -- A data object obtained from the StatusNet server containing a complete update |
1066 | + |
1067 | + Returns: |
1068 | + m -- A data object compatible with inserting into the Gwibber database for that tweet |
1069 | + |
1070 | """ |
1071 | if type(data) != dict: |
1072 | logger.error("Cannot parse message data: %s", str(data)) |
1073 | @@ -167,7 +186,7 @@ |
1074 | m = self._common(data) |
1075 | for k in n: |
1076 | m[k] = n[k] |
1077 | - |
1078 | + |
1079 | if data.has_key("in_reply_to_status_id"): |
1080 | if data["in_reply_to_status_id"]: |
1081 | m["reply"] = {} |
1082 | @@ -184,13 +203,21 @@ |
1083 | return m |
1084 | |
1085 | def _private(self, data): |
1086 | - """ Sets the message type and privacy if the message should be in the private stream. |
1087 | - Also parses the recipient as both sent & recieved messages can be in the private stream. |
1088 | + """Sets the message type and privacy. |
1089 | + |
1090 | + Sets the message type and privacy if the |
1091 | + message should be in the private stream. |
1092 | + |
1093 | + Also parses the recipient as both sent & |
1094 | + received messages can be in the private stream. |
1095 | It sends the rest to _message() for further parsing |
1096 | - Args: |
1097 | - data: A data object obtained from the StatusNet server containing a complete update |
1098 | - Returns: |
1099 | - m: A data object compatible with inserting into the Gwibber database for that update |
1100 | + |
1101 | + Arguments: |
1102 | + data -- A data object obtained from the StatusNet server containing a complete update |
1103 | + |
1104 | + Returns: |
1105 | + m -- A data object compatible with inserting into the Gwibber database for that update |
1106 | + |
1107 | """ |
1108 | m = self._message(data) |
1109 | m["private"] = True |
1110 | @@ -206,15 +233,20 @@ |
1111 | return m |
1112 | |
1113 | def _result(self, data): |
1114 | - """ Called when a search is done in gwibber. Parses the sender and sends the rest to _common() |
1115 | - for further parsing |
1116 | - Args: |
1117 | - data: A data object obtained from the StatusNet server containing a complete update |
1118 | - Returns: |
1119 | - m: A data object compatible with inserting into the Gwibber database for that update |
1120 | + """Called when a search is done in Gwibber. |
1121 | + |
1122 | + Parses the sender and sends the rest to _common() |
1123 | + for further parsing. |
1124 | + |
1125 | + Args: |
1126 | + data -- A data object obtained from the StatusNet server containing a complete update |
1127 | + |
1128 | + Returns: |
1129 | + m -- A data object compatible with inserting into the Gwibber database for that update |
1130 | + |
1131 | """ |
1132 | m = self._common(data) |
1133 | - |
1134 | + |
1135 | if data["to_user_id"]: |
1136 | m["reply"] = {} |
1137 | m["reply"]["id"] = data["to_user_id"] |
1138 | @@ -229,11 +261,14 @@ |
1139 | return m |
1140 | |
1141 | def _profile(self, data): |
1142 | - """ Called when a user is clicked on. |
1143 | - Args: |
1144 | - data: A data object obtained from the StatusNet server containing a complete user |
1145 | - Returns: |
1146 | - A data object compatible with inserting into the Gwibber database for that user |
1147 | + """Called when a user is clicked on. |
1148 | + |
1149 | + Arguments: |
1150 | + data -- A data object obtained from the StatusNet server containing a complete user |
1151 | + |
1152 | + Returns: |
1153 | + A data object compatible with inserting into the Gwibber database for that user. |
1154 | + |
1155 | """ |
1156 | return { |
1157 | "name": data.get("name", data["screen_name"]), |
1158 | @@ -260,15 +295,20 @@ |
1159 | } |
1160 | |
1161 | def _get(self, path, parse="message", post=False, single=False, **args): |
1162 | - """ Establishes a connection with the StatusNet server and gets the data requested. Requires authentication. |
1163 | - Args: |
1164 | - path: The end of the url to look up on the StatusNet server |
1165 | - parse: The function to use to parse the data returned (message by default) |
1166 | - post: True is this is a send, False if a recieve (False by default) |
1167 | - single: True if a single checkin is requested, False if multiple (False by default) |
1168 | - **args: Args to be added to the url when accessed. |
1169 | + """Establishes a connection with the StatusNet server and gets the data requested. |
1170 | + |
1171 | + Requires authentication. |
1172 | + |
1173 | + Arguments: |
1174 | + path -- The end of the URL to look up on the StatusNet server |
1175 | + parse -- The function to use to parse the data returned (message by default) |
1176 | + post -- True if using POST, for example the send operation. False if using GET, most operations other than send. (False by default) |
1177 | + single -- True if a single checkin is requested, False if multiple (False by default) |
1178 | + **args -- Arguments to be added to the URL when accessed |
1179 | + |
1180 | Returns: |
1181 | - A list of gwibber compatible objects which have been parsed by the parse function |
1182 | + A list of Gwibber compatible objects which have been parsed by the parse function. |
1183 | + |
1184 | """ |
1185 | if not self.account.has_key("access_token") and not self.account.has_key("secret_token"): |
1186 | logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], _("Account needs to be re-authorized")) |
1187 | @@ -320,12 +360,16 @@ |
1188 | return [self._result(m) for m in data] |
1189 | |
1190 | def _search(self, **args): |
1191 | - """ Establishes a connection with the StatusNet server and gets the results of a search. |
1192 | + """Establishes a connection with the StatusNet server and gets the results of a search. |
1193 | + |
1194 | Does not require authentication |
1195 | - Args: |
1196 | - **args: |
1197 | + |
1198 | + Arguments: |
1199 | + **args -- Example, if _search(tag=bar,name=foo) then **args is tag, name |
1200 | + |
1201 | Returns: |
1202 | - A list of gwibber compatible objects which have been parsed by _result() |
1203 | + A list of Gwibber compatible objects which have been parsed by _result(). |
1204 | + |
1205 | """ |
1206 | data = network.Download("%s/api/search.json" % self.account["url_prefix"], util.compact(args)) |
1207 | data = data.get_json() |
1208 | @@ -338,160 +382,207 @@ |
1209 | |
1210 | def __call__(self, opname, **args): |
1211 | return getattr(self, opname)(**args) |
1212 | - |
1213 | + |
1214 | def receive(self, count=util.COUNT, since=None): |
1215 | - """ Gets the latest updates and adds them to the database. |
1216 | - Args: |
1217 | - None |
1218 | + """Gets the latest updates and adds them to the database. |
1219 | + |
1220 | + Arguments: |
1221 | + None |
1222 | + |
1223 | Returns: |
1224 | - A list of gwibber compatible objects which have been parsed by _message() |
1225 | + A list of Gwibber compatible objects which have been parsed by _message(). |
1226 | + |
1227 | """ |
1228 | return self._get("statuses/friends_timeline.json", count=count, since_id=since, source="Gwibber") |
1229 | |
1230 | def responses(self, count=util.COUNT, since=None): |
1231 | - """ Gets the latest replies and adds them to the database. |
1232 | - Args: |
1233 | - None |
1234 | + """Gets the latest replies and adds them to the database. |
1235 | + |
1236 | + Arguments: |
1237 | + None |
1238 | + |
1239 | Returns: |
1240 | - A list of gwibber compatible objects which have been parsed by _responses() |
1241 | + A list of Gwibber compatible objects which have been parsed by _responses(). |
1242 | + |
1243 | """ |
1244 | return self._get("statuses/mentions.json", count=count, since_id=since, source="Gwibber") |
1245 | |
1246 | def private(self, count=util.COUNT, since=None): |
1247 | - """ Gets the latest direct messages sent and recieved and adds them to the database. |
1248 | - Args: |
1249 | - None |
1250 | + """Gets the latest direct messages sent and received and adds them to the database. |
1251 | + |
1252 | + Arguments: |
1253 | + None |
1254 | + |
1255 | Returns: |
1256 | - A list of gwibber compatible objects which have been parsed by _private() |
1257 | + A list of Gwibber compatible objects which have been parsed by _private(). |
1258 | + |
1259 | """ |
1260 | private = self._get("direct_messages.json", "private", count=count, since_id=since, source="Gwibber") or [] |
1261 | private_sent = self._get("direct_messages/sent.json", "private", count=count, since_id=since, source="Gwibber") or [] |
1262 | return private + private_sent |
1263 | |
1264 | def public(self, count=util.COUNT, since=None): |
1265 | - """ Gets the latest updates from the public timeline and adds them to the database. |
1266 | - Args: |
1267 | - None |
1268 | + """Gets the latest updates from the public timeline and adds them to the database. |
1269 | + |
1270 | + Arguments: |
1271 | + None |
1272 | + |
1273 | Returns: |
1274 | - A list of gwibber compatible objects which have been parsed by _message() |
1275 | + A list of Gwibber compatible objects which have been parsed by _message(). |
1276 | + |
1277 | """ |
1278 | return self._get("statuses/public_timeline.json", source="Gwibber") |
1279 | |
1280 | def search(self, query, count=util.COUNT, since=None): |
1281 | - """ Gets the latest results from a search and adds them to the database. |
1282 | - Args: |
1283 | - None |
1284 | + """Gets the latest results from a search and adds them to the database. |
1285 | + |
1286 | + Arguments: |
1287 | + None |
1288 | + |
1289 | Returns: |
1290 | - A list of gwibber compatible objects which have been parsed by _search() |
1291 | + A list of Gwibber compatible objects which have been parsed by _search(). |
1292 | + |
1293 | """ |
1294 | return self._search(q=query, rpp=count, since_id=since, source="Gwibber") |
1295 | |
1296 | def tag(self, query, count=util.COUNT, since=None): |
1297 | - """ Gets the latest results from a hashtag search and adds them to the database. |
1298 | - Args: |
1299 | - None |
1300 | + """Gets the latest results from a hashtag search and adds them to the database. |
1301 | + |
1302 | + Arguments: |
1303 | + None |
1304 | + |
1305 | Returns: |
1306 | - A list of gwibber compatible objects which have been parsed by _search() |
1307 | + A list of Gwibber compatible objects which have been parsed by _search() |
1308 | + |
1309 | """ |
1310 | return self._search(q="#%s" % query, count=count, since_id=since, source="Gwibber") |
1311 | |
1312 | def delete(self, message): |
1313 | - """ Deletes a specified update from the StatusNet server |
1314 | - Args: |
1315 | - message: a gwibber compatible message object (from gwibber's database) |
1316 | + """Deletes a specified update from the StatusNet server. |
1317 | + |
1318 | + Arguments: |
1319 | + message -- A Gwibber compatible message object (from Gwibber's database) |
1320 | + |
1321 | Returns: |
1322 | - Nothing |
1323 | + Nothing |
1324 | + |
1325 | """ |
1326 | self._get("statuses/destroy/%s.json" % message["mid"], None, post=True, do=1, source="Gwibber") |
1327 | return [] |
1328 | |
1329 | def like(self, message): |
1330 | - """ Favourites a specified update on the StatusNet server |
1331 | - Args: |
1332 | - message: a gwibber compatible message object (from gwibber's database) |
1333 | + """Favorites a specified update on the StatusNet server. |
1334 | + |
1335 | + Arguments: |
1336 | + message -- A Gwibber compatible message object (from Gwibber's database) |
1337 | + |
1338 | Returns: |
1339 | - Nothing |
1340 | + Nothing |
1341 | + |
1342 | """ |
1343 | self._get("favorites/create/%s.json" % message["mid"], None, post=True, do=1, source="Gwibber") |
1344 | return [] |
1345 | |
1346 | def send(self, message): |
1347 | - """ Sends a message to the StatusNet server |
1348 | - Args: |
1349 | - message: The update's text |
1350 | + """Sends a message to the StatusNet server. |
1351 | + |
1352 | + Arguments: |
1353 | + message -- The update's text |
1354 | + |
1355 | Returns: |
1356 | - Nothing |
1357 | + Nothing |
1358 | + |
1359 | """ |
1360 | return self._get("statuses/update.json", post=True, single=True, status=message, source="Gwibber") |
1361 | |
1362 | def send_private(self, message, private): |
1363 | - """ Sends a direct message to the StatusNet server |
1364 | - Args: |
1365 | - message: The update's text |
1366 | - private: A gwibber compatible user object (from gwibber's database) |
1367 | + """Sends a direct message to the StatusNet server. |
1368 | + |
1369 | + Arguments: |
1370 | + message -- The update's text |
1371 | + private -- A Gwibber compatible user object (from Gwibber's database) |
1372 | + |
1373 | Returns: |
1374 | - Nothing |
1375 | + Nothing |
1376 | + |
1377 | """ |
1378 | return self._get("direct_messages/new.json", "private", post=True, single=True, |
1379 | text=message, screen_name=private["sender"]["nick"], source="Gwibber") |
1380 | |
1381 | def send_thread(self, message, target): |
1382 | - """ Sends a reply to a user on the StatusNet server |
1383 | - Args: |
1384 | - message: The update's text |
1385 | - target: A gwibber compatible user object (from gwibber's database) |
1386 | + """Sends a reply to a user on the StatusNet server. |
1387 | + |
1388 | + Arguments: |
1389 | + message -- The update's text |
1390 | + target -- A Gwibber compatible user object (from Gwibber's database) |
1391 | + |
1392 | Returns: |
1393 | - Nothing |
1394 | + Nothing |
1395 | + |
1396 | """ |
1397 | return self._get("statuses/update.json", post=True, single=True, |
1398 | status=message, in_reply_to_status_id=target["mid"], source="Gwibber") |
1399 | |
1400 | def retweet(self, message): |
1401 | - """ Shares an update |
1402 | - Args: |
1403 | - message: A gwibber compatible message object (from gwibber's database) |
1404 | + """Shares an update. |
1405 | + Arguments: |
1406 | + message -- A Gwibber compatible message object (from Gwibber's database) |
1407 | + |
1408 | Returns: |
1409 | - Nothing |
1410 | + Nothing |
1411 | + |
1412 | """ |
1413 | return self._get("statuses/retweet/%s.json" % message["mid"], None, post=True, do=1, source="Gwibber") |
1414 | |
1415 | def follow(self, screen_name): |
1416 | - """ Follows a user |
1417 | - Args: |
1418 | - screen_name: The screen name of the user to be followed |
1419 | + """Follows a user. |
1420 | + |
1421 | + Arguments: |
1422 | + screen_name -- The screen name of the user to be followed |
1423 | + |
1424 | Returns: |
1425 | - Nothing |
1426 | + Nothing |
1427 | + |
1428 | """ |
1429 | return self._get("friendships/create.json", screen_name=screen_name, post=True, parse="follow", source="Gwibber") |
1430 | |
1431 | def unfollow(self, screen_name): |
1432 | - """ Unfollows a user |
1433 | - Args: |
1434 | - screen_name: The screen name of the user to be unfollowed |
1435 | + """Unfollows a user. |
1436 | + |
1437 | + Arguments: |
1438 | + screen_name -- The screen name of the user to be unfollowed |
1439 | + |
1440 | Returns: |
1441 | - Nothing |
1442 | + Nothing |
1443 | + |
1444 | """ |
1445 | return self._get("friendships/destroy.json", screen_name=screen_name, post=True, parse="unfollow", source="Gwibber") |
1446 | |
1447 | def profile(self, id=None, count=None, since=None): |
1448 | - """ Gets a user's profile |
1449 | - Args: |
1450 | - id: The user's screen name |
1451 | - count: Number of updates to get |
1452 | - since: Time to get updates since |
1453 | + """Gets a user's profile. |
1454 | + |
1455 | + Arguments: |
1456 | + id -- The user's screen name |
1457 | + count -- Number of updates to get |
1458 | + since -- Time to get updates since |
1459 | + |
1460 | Returns: |
1461 | - A list of gwibber compatible objects which have been parsed by _profile() |
1462 | + A list of Gwibber compatible objects which have been parsed by _profile(). |
1463 | + |
1464 | """ |
1465 | return self._get("users/show.json", screen_name=id, count=count, since_id=since, parse="profile", source="Gwibber") |
1466 | |
1467 | def user_messages(self, id=None, count=util.COUNT, since=None): |
1468 | - """ Gets a user's profile & timeline |
1469 | - Args: |
1470 | - id: The user's screen name |
1471 | - count: Number of updates to get |
1472 | - since: Time to get updates since |
1473 | + """Gets a user's profile & timeline. |
1474 | + |
1475 | + Arguments: |
1476 | + id -- The user's screen name |
1477 | + count -- Number of updates to get |
1478 | + since -- Time to get updates since |
1479 | + |
1480 | Returns: |
1481 | - A list of gwibber compatible objects which have been parsed by _profile() |
1482 | + A list of Gwibber compatible objects which have been parsed by _profile(). |
1483 | + |
1484 | """ |
1485 | profiles = [self.profile(id)] or [] |
1486 | messages = self._get("statuses/user_timeline.json", id=id, count=count, since_id=since, source="Gwibber") or [] |
1487 | |
1488 | === modified file 'gwibber/microblog/plugins/twitter/__init__.py' |
1489 | --- gwibber/microblog/plugins/twitter/__init__.py 2012-05-23 14:02:10 +0000 |
1490 | +++ gwibber/microblog/plugins/twitter/__init__.py 2012-06-12 20:30:26 +0000 |
1491 | @@ -62,10 +62,14 @@ |
1492 | API_PREFIX = "https://api.twitter.com/1" |
1493 | |
1494 | class Client (): |
1495 | - """ Client: The Client class is responsible for querying Twitter and turning the data obtained |
1496 | - into data that Gwibber can understand. Twitter uses a version of oauth for security. |
1497 | + """Querys Twitter and converts the data. |
1498 | + |
1499 | + The Client class is responsible for querying Twitter and turning the data obtained |
1500 | + into data that Gwibber can understand. Twitter uses a version of OAuth for security. |
1501 | + |
1502 | Tokens have already been obtained when the account was set up in Gwibber and are used to |
1503 | authenticate when getting data. |
1504 | + |
1505 | """ |
1506 | def __init__(self, acct): |
1507 | self.service = util.getbus("Service") |
1508 | @@ -80,12 +84,18 @@ |
1509 | self.token = oauth.OAuthToken(acct["access_token"], acct["secret_token"]) |
1510 | |
1511 | def _common(self, data): |
1512 | - """ Parses messages into gwibber compatible forms. This function is common to all tweet types |
1513 | - and includes parsing of user mentions, hashtags, urls, images and videos |
1514 | - Args: |
1515 | - data: A data object obtained from Twitter containing a complete tweet |
1516 | + """Parses messages into Gwibber compatible forms. |
1517 | + |
1518 | + This function is common to all tweet types |
1519 | + and includes parsing of user mentions, hashtags, |
1520 | + urls, images and videos. |
1521 | + |
1522 | + Arguments: |
1523 | + data -- A data object obtained from Twitter containing a complete tweet |
1524 | + |
1525 | Returns: |
1526 | - m: A data object compatible with inserting into the Gwibber database for that tweet |
1527 | + m -- A data object compatible with inserting into the Gwibber database for that tweet |
1528 | + |
1529 | """ |
1530 | m = {} |
1531 | try: |
1532 | @@ -215,11 +225,14 @@ |
1533 | return m |
1534 | |
1535 | def _user(self, user): |
1536 | - """ Parses the user portion of a tweet |
1537 | - Args: |
1538 | - user: A user object from a tweet |
1539 | + """Parses the user portion of a tweet. |
1540 | + |
1541 | + Arguments: |
1542 | + user -- A user object from a tweet |
1543 | + |
1544 | Returns: |
1545 | - A user object in a format compatible with gwibber's database |
1546 | + A user object in a format compatible with Gwibber's database. |
1547 | + |
1548 | """ |
1549 | return { |
1550 | "name": user.get("name", None), |
1551 | @@ -239,13 +252,19 @@ |
1552 | } |
1553 | |
1554 | def _message(self, data): |
1555 | - """ Parses messages into gwibber compatible forms. This is the initial function for |
1556 | - tweet parsing and parses retweeted status (the shared-by portion), source (the program the tweet was tweeted from) |
1557 | - and reply details (the in-reply-to portion). It sends the rest to _common() for further parsing |
1558 | - Args: |
1559 | - data: A data object obtained from Twitter containing a complete tweet |
1560 | + """Parses messages into gwibber compatible forms. |
1561 | + |
1562 | + This is the initial function for tweet parsing and parses |
1563 | + retweeted status (the shared-by portion), source (the program |
1564 | + the tweet was tweeted from) and reply details (the in-reply-to |
1565 | + portion). It sends the rest to _common() for further parsing. |
1566 | + |
1567 | + Arguments: |
1568 | + data -- A data object obtained from Twitter containing a complete tweet |
1569 | + |
1570 | Returns: |
1571 | - m: A data object compatible with inserting into the Gwibber database for that tweet |
1572 | + m -- A data object compatible with inserting into the Gwibber database for that tweet |
1573 | + |
1574 | """ |
1575 | if type(data) != dict: |
1576 | logger.error("Cannot parse message data: %s", str(data)) |
1577 | @@ -284,12 +303,16 @@ |
1578 | return m |
1579 | |
1580 | def _responses(self, data): |
1581 | - """ Sets the message type if the message should be in the replies stream. |
1582 | - It sends the rest to _message() for further parsing |
1583 | - Args: |
1584 | - data: A data object obtained from Twitter containing a complete tweet |
1585 | + """Sets the message type if the message should be in the replies stream. |
1586 | + |
1587 | + It sends the rest to _message() for further parsing. |
1588 | + |
1589 | + Arguments: |
1590 | + data -- A data object obtained from Twitter containing a complete tweet |
1591 | + |
1592 | Returns: |
1593 | - m: A data object compatible with inserting into the Gwibber database for that tweet |
1594 | + m -- A data object compatible with inserting into the Gwibber database for that tweet |
1595 | + |
1596 | """ |
1597 | m = self._message(data) |
1598 | m["type"] = None |
1599 | @@ -297,13 +320,18 @@ |
1600 | return m |
1601 | |
1602 | def _private(self, data): |
1603 | - """ Sets the message type and privacy if the message should be in the private stream. |
1604 | + """Sets the message type and privacy. |
1605 | + |
1606 | + Sets the message type and privacy if the message should be in the private stream. |
1607 | Also parses the recipient as both sent & recieved messages can be in the private stream. |
1608 | It sends the rest to _message() for further parsing |
1609 | - Args: |
1610 | - data: A data object obtained from Twitter containing a complete tweet |
1611 | + |
1612 | + Arguments: |
1613 | + data -- A data object obtained from Twitter containing a complete tweet |
1614 | + |
1615 | Returns: |
1616 | - m: A data object compatible with inserting into the Gwibber database for that tweet |
1617 | + m -- A data object compatible with inserting into the Gwibber database for that tweet |
1618 | + |
1619 | """ |
1620 | m = self._message(data) |
1621 | m["private"] = True |
1622 | @@ -322,12 +350,17 @@ |
1623 | return m |
1624 | |
1625 | def _result(self, data): |
1626 | - """ Called when a search is done in gwibber. Parses the sender and sends the rest to _common() |
1627 | - for further parsing |
1628 | - Args: |
1629 | - data: A data object obtained from Twitter containing a complete tweet |
1630 | + """Called when a search is done in Gwibber. |
1631 | + |
1632 | + Parses the sender and sends the rest to _common() |
1633 | + for further parsing. |
1634 | + |
1635 | + Arguments: |
1636 | + data -- A data object obtained from Twitter containing a complete tweet |
1637 | + |
1638 | Returns: |
1639 | - m: A data object compatible with inserting into the Gwibber database for that tweet |
1640 | + m -- A data object compatible with inserting into the Gwibber database for that tweet |
1641 | + |
1642 | """ |
1643 | m = self._common(data) |
1644 | |
1645 | @@ -346,11 +379,14 @@ |
1646 | return m |
1647 | |
1648 | def _profile(self, data): |
1649 | - """ Called when a user is clicked on. |
1650 | + """Called when a user is clicked on. |
1651 | + |
1652 | Args: |
1653 | - data: A data object obtained from Twitter containing a complete user |
1654 | + data -- A data object obtained from Twitter containing a complete user |
1655 | + |
1656 | Returns: |
1657 | - A data object compatible with inserting into the Gwibber database for that user |
1658 | + A data object compatible with inserting into the Gwibber database for that user. |
1659 | + |
1660 | """ |
1661 | if "error" in data: |
1662 | return { |
1663 | @@ -381,11 +417,14 @@ |
1664 | } |
1665 | |
1666 | def _list(self, data): |
1667 | - """ Called when a list is clicked on. |
1668 | + """Called when a list is clicked on. |
1669 | + |
1670 | Args: |
1671 | - data: A data object obtained from Twitter containing a complete list |
1672 | + data -- A data object obtained from Twitter containing a complete list |
1673 | + |
1674 | Returns: |
1675 | - A data object compatible with inserting into the Gwibber database for that list |
1676 | + A data object compatible with inserting into the Gwibber database for that list. |
1677 | + |
1678 | """ |
1679 | return { |
1680 | "mid": data["id"], |
1681 | @@ -409,15 +448,20 @@ |
1682 | } |
1683 | |
1684 | def _get(self, path, parse="message", post=False, single=False, **args): |
1685 | - """ Establishes a connection with Twitter and gets the data requested. Requires authentication. |
1686 | - Args: |
1687 | - path: The end of the url to look up on Twitter |
1688 | - parse: The function to use to parse the data returned (message by default) |
1689 | - post: True is this is a send, False if a recieve (False by default) |
1690 | - single: True if a single checkin is requested, False if multiple (False by default) |
1691 | - **args: Args to be added to the url when accessed. |
1692 | + """Establishes a connection with Twitter and gets the data requested. |
1693 | + |
1694 | + Requires authentication. |
1695 | + |
1696 | + Arguments: |
1697 | + path -- The end of the url to look up on Twitter |
1698 | + parse -- The function to use to parse the data returned (message by default) |
1699 | + post -- True if using POST, for example the send operation. False if using GET, most operations other than send. (False by default) |
1700 | + single -- True if a single checkin is requested, False if multiple (False by default) |
1701 | + **args -- Arguments to be added to the URL when accessed. |
1702 | + |
1703 | Returns: |
1704 | - A list of gwibber compatible objects which have been parsed by the parse function |
1705 | + A list of Gwibber compatible objects which have been parsed by the parse function. |
1706 | + |
1707 | """ |
1708 | url = "/".join((API_PREFIX, path)) |
1709 | |
1710 | @@ -470,12 +514,16 @@ |
1711 | else: return [] |
1712 | |
1713 | def _search(self, **args): |
1714 | - """ Establishes a connection with Twitter and gets the results of a search. |
1715 | + """Establishes a connection with Twitter and gets the results of a search. |
1716 | + |
1717 | Does not require authentication |
1718 | - Args: |
1719 | - **args: The search terms |
1720 | + |
1721 | + Arguments: |
1722 | + **args -- The search terms |
1723 | + |
1724 | Returns: |
1725 | - A list of gwibber compatible objects which have been parsed by _result() |
1726 | + A list of Gwibber compatible objects which have been parsed by _result(). |
1727 | + |
1728 | """ |
1729 | data = network.Download("http://search.twitter.com/search.json", util.compact(args)) |
1730 | data = data.get_json()["results"] |
1731 | @@ -490,187 +538,241 @@ |
1732 | return getattr(self, opname)(**args) |
1733 | |
1734 | def receive(self, count=util.COUNT, since=None): |
1735 | - """ Gets the latest tweets and adds them to the database. |
1736 | - Args: |
1737 | - count = number of updates to get |
1738 | - since = time to get updates since |
1739 | + """Gets the latest tweets and adds them to the database. |
1740 | + |
1741 | + Arguments: |
1742 | + count -- Number of updates to get |
1743 | + since -- Time to get updates since |
1744 | + |
1745 | Returns: |
1746 | - A list of gwibber compatible objects which have been parsed by _message() |
1747 | + A list of Gwibber compatible objects which have been parsed by _message(). |
1748 | + |
1749 | """ |
1750 | return self._get("statuses/home_timeline.json", include_entities=1, count=count, since_id=since) |
1751 | |
1752 | def responses(self, count=util.COUNT, since=None): |
1753 | - """ Gets the latest replies and adds them to the database. |
1754 | - Args: |
1755 | - count = number of updates to get |
1756 | - since = time to get updates since |
1757 | + """Gets the latest replies and adds them to the database. |
1758 | + |
1759 | + Arguments: |
1760 | + count -- Number of updates to get |
1761 | + since -- Time to get updates since |
1762 | + |
1763 | Returns: |
1764 | - A list of gwibber compatible objects which have been parsed by _responses() |
1765 | + A list of Gwibber compatible objects which have been parsed by _responses(). |
1766 | + |
1767 | """ |
1768 | return self._get("statuses/mentions.json", "responses", include_entities=1, count=count, since_id=since) |
1769 | |
1770 | def private(self, count=util.COUNT, since=None): |
1771 | - """ Gets the latest direct messages sent and recieved and adds them to the database. |
1772 | + """Gets the latest direct messages sent and recieved and adds them to the database. |
1773 | + |
1774 | Args: |
1775 | - count = number of updates to get |
1776 | - since = time to get updates since |
1777 | + count -- Number of updates to get |
1778 | + since -- Time to get updates since |
1779 | + |
1780 | Returns: |
1781 | - A list of gwibber compatible objects which have been parsed by _private() |
1782 | + A list of Gwibber compatible objects which have been parsed by _private(). |
1783 | + |
1784 | """ |
1785 | private = self._get("direct_messages.json", "private", include_entities=1, count=count, since_id=since) or [] |
1786 | private_sent = self._get("direct_messages/sent.json", "private", count=count, since_id=since) or [] |
1787 | return private + private_sent |
1788 | |
1789 | def public(self): |
1790 | - """ Gets the latest tweets from the public timeline and adds them to the database. |
1791 | - Args: |
1792 | - None |
1793 | + """Gets the latest tweets from the public timeline and adds them to the database. |
1794 | + |
1795 | + Arguments: |
1796 | + None |
1797 | + |
1798 | Returns: |
1799 | - A list of gwibber compatible objects which have been parsed by _message() |
1800 | + A list of Gwibber compatible objects which have been parsed by _message(). |
1801 | + |
1802 | """ |
1803 | return self._get("statuses/public_timeline.json", include_entities=1) |
1804 | |
1805 | def lists(self, **args): |
1806 | - """ Gets subscribed lists and adds them to the database. |
1807 | - Args: |
1808 | - None |
1809 | + """Gets subscribed lists and adds them to the database. |
1810 | + |
1811 | + Arguments: |
1812 | + None |
1813 | + |
1814 | Returns: |
1815 | - A list of gwibber compatible objects which have been parsed by _list() |
1816 | + A list of Gwibber compatible objects which have been parsed by _list(). |
1817 | + |
1818 | """ |
1819 | following = self._get("%s/lists/subscriptions.json" % self.account["username"], "list") or [] |
1820 | lists = self._get("%s/lists.json" % self.account["username"], "list") or [] |
1821 | return following + lists |
1822 | |
1823 | def list(self, user, id, count=util.COUNT, since=None): |
1824 | - """ Gets the latest tweets from subscribed lists and adds them to the database. |
1825 | - Args: |
1826 | - user = the user's name whose lists are to be got |
1827 | - id = the user's id whose lists are to be got |
1828 | - count = number of updates to get |
1829 | - since = time to get updates since |
1830 | + """Gets the latest tweets from subscribed lists and adds them to the database. |
1831 | + |
1832 | + Arguments: |
1833 | + user -- The user's name whose lists are to be got |
1834 | + id -- The user's id whose lists are to be got |
1835 | + count -- Number of updates to get |
1836 | + since -- Time to get updates since |
1837 | + |
1838 | Returns: |
1839 | - A list of gwibber compatible objects which have been parsed by _message() |
1840 | + A list of Gwibber compatible objects which have been parsed by _message(). |
1841 | + |
1842 | """ |
1843 | return self._get("%s/lists/%s/statuses.json" % (user, id), include_entities=1, per_page=count, since_id=since) |
1844 | |
1845 | def search(self, query, count=util.COUNT, since=None): |
1846 | - """ Gets the latest results from a search and adds them to the database. |
1847 | - Args: |
1848 | - query = the search query |
1849 | - count = number of updates to get |
1850 | - since = time to get updates since |
1851 | + """Gets the latest results from a search and adds them to the database. |
1852 | + |
1853 | + Arguments: |
1854 | + query -- The search query |
1855 | + count -- Number of updates to get |
1856 | + since -- Time to get updates since |
1857 | + |
1858 | Returns: |
1859 | - A list of gwibber compatible objects which have been parsed by _search() |
1860 | + A list of Gwibber compatible objects which have been parsed by _search(). |
1861 | + |
1862 | """ |
1863 | return self._search(include_entities=1, q=query, rpp=count, since_id=since) |
1864 | |
1865 | def tag(self, query, count=util.COUNT, since=None): |
1866 | - """ Gets the latest results from a hashtag search and adds them to the database. |
1867 | - Args: |
1868 | - query = the search query (hashtag without the #) |
1869 | - count = number of updates to get |
1870 | - since = time to get updates since |
1871 | + """Gets the latest results from a hashtag search and adds them to the database. |
1872 | + |
1873 | + Arguments: |
1874 | + query -- The search query (hashtag without the #) |
1875 | + count -- Number of updates to get |
1876 | + since -- Time to get updates since |
1877 | + |
1878 | Returns: |
1879 | - A list of gwibber compatible objects which have been parsed by _search() |
1880 | + A list of Gwibber compatible objects which have been parsed by _search(). |
1881 | + |
1882 | """ |
1883 | return self._search(q="#%s" % query, count=count, since_id=since) |
1884 | |
1885 | def delete(self, message): |
1886 | - """ Deletes a specified tweet from twitter |
1887 | - Args: |
1888 | - message: a gwibber compatible message object (from gwibber's database) |
1889 | + """Deletes a specified tweet from Twitter. |
1890 | + |
1891 | + Arguments: |
1892 | + message -- A Gwibber compatible message object (from gwibber's database) |
1893 | + |
1894 | Returns: |
1895 | - Nothing |
1896 | + Nothing |
1897 | + |
1898 | """ |
1899 | return self._get("statuses/destroy/%s.json" % message["mid"], None, post=True, do=1) |
1900 | |
1901 | def like(self, message): |
1902 | - """ Favourites a specified tweet on twitter |
1903 | - Args: |
1904 | - message: a gwibber compatible message object (from gwibber's database) |
1905 | + """Favourites a specified tweet on Twitter. |
1906 | + |
1907 | + Arguments: |
1908 | + message -- A Gwibber compatible message object (from Gwibber's database) |
1909 | + |
1910 | Returns: |
1911 | - Nothing |
1912 | + Nothing |
1913 | + |
1914 | """ |
1915 | return self._get("favorites/create/%s.json" % message["mid"], None, post=True, do=1) |
1916 | |
1917 | def send(self, message): |
1918 | - """ Sends a tweet to twitter |
1919 | - Args: |
1920 | - message: The tweet's text |
1921 | + """Sends a tweet to Twitter. |
1922 | + |
1923 | + Arguments: |
1924 | + message -- The tweet's text |
1925 | + |
1926 | Returns: |
1927 | - Nothing |
1928 | + Nothing |
1929 | + |
1930 | """ |
1931 | return self._get("statuses/update.json", post=True, single=True, |
1932 | status=message) |
1933 | |
1934 | def send_private(self, message, private): |
1935 | - """ Sends a direct message to twitter |
1936 | - Args: |
1937 | - message: The tweet's text |
1938 | - private: A gwibber compatible user object (from gwibber's database) |
1939 | + """Sends a direct message to Twitter. |
1940 | + |
1941 | + Arguments: |
1942 | + message -- The tweet's text |
1943 | + private -- A gwibber compatible user object (from gwibber's database) |
1944 | + |
1945 | Returns: |
1946 | - Nothing |
1947 | + Nothing |
1948 | + |
1949 | """ |
1950 | return self._get("direct_messages/new.json", "private", post=True, single=True, |
1951 | text=message, screen_name=private["sender"]["nick"]) |
1952 | |
1953 | def send_thread(self, message, target): |
1954 | - """ Sends a reply to a user on twitter |
1955 | - Args: |
1956 | - message: The tweet's text |
1957 | - target: A gwibber compatible user object (from gwibber's database) |
1958 | + """Sends a reply to a user on Twitter. |
1959 | + |
1960 | + Arguments: |
1961 | + message -- The tweet's text |
1962 | + target -- A Gwibber compatible user object (from Gwibber's database) |
1963 | + |
1964 | Returns: |
1965 | - Nothing |
1966 | + Nothing |
1967 | + |
1968 | """ |
1969 | return self._get("statuses/update.json", post=True, single=True, |
1970 | status=message, in_reply_to_status_id=target["mid"]) |
1971 | |
1972 | def retweet(self, message): |
1973 | - """ Retweets a tweet |
1974 | - Args: |
1975 | - message: A gwibber compatible message object (from gwibber's database) |
1976 | + """Retweets a tweet. |
1977 | + |
1978 | + Arguments: |
1979 | + message -- A Gwibber compatible message object (from gwibber's database) |
1980 | + |
1981 | Returns: |
1982 | - Nothing |
1983 | + Nothing |
1984 | + |
1985 | """ |
1986 | return self._get("statuses/retweet/%s.json" % message["mid"], None, post=True, do=1) |
1987 | |
1988 | def follow(self, screen_name): |
1989 | - """ Follows a user |
1990 | - Args: |
1991 | - screen_name: The screen name (@someone without the @) of the user to be followed |
1992 | + """Follows a user. |
1993 | + |
1994 | + Arguments: |
1995 | + screen_name -- The screen name (@someone without the @) of the user to be followed |
1996 | + |
1997 | Returns: |
1998 | - Nothing |
1999 | + Nothing |
2000 | + |
2001 | """ |
2002 | return self._get("friendships/create.json", screen_name=screen_name, post=True, parse="follow") |
2003 | |
2004 | def unfollow(self, screen_name): |
2005 | - """ Unfollows a user |
2006 | - Args: |
2007 | - screen_name: The screen name (@someone without the @) of the user to be unfollowed |
2008 | + """Unfollows a user. |
2009 | + |
2010 | + Arguments: |
2011 | + screen_name -- The screen name (@someone without the @) of the user to be unfollowed |
2012 | + |
2013 | Returns: |
2014 | - Nothing |
2015 | + Nothing |
2016 | + |
2017 | """ |
2018 | return self._get("friendships/destroy.json", screen_name=screen_name, post=True, parse="unfollow") |
2019 | |
2020 | def profile(self, id=None, count=None, since=None): |
2021 | - """ Gets a user's profile |
2022 | - Args: |
2023 | - id: The user's screen name |
2024 | - count: Number of tweets to get |
2025 | - since: Time to get tweets since |
2026 | + """Gets a user's profile. |
2027 | + |
2028 | + Arguments: |
2029 | + id -- The user's screen name |
2030 | + count -- Number of tweets to get |
2031 | + since -- Time to get tweets since |
2032 | + |
2033 | Returns: |
2034 | - A list of gwibber compatible objects which have been parsed by _profile() |
2035 | + A list of Gwibber compatible objects which have been parsed by _profile(). |
2036 | + |
2037 | """ |
2038 | return self._get("users/show.json", screen_name=id, count=count, since_id=since, parse="profile") |
2039 | |
2040 | def user_messages(self, id=None, count=util.COUNT, since=None): |
2041 | - """ Gets a user's profile & timeline |
2042 | - Args: |
2043 | - id: The user's screen name |
2044 | - count: Number of tweets to get |
2045 | - since: Time to get tweets since |
2046 | + """Gets a user's profile & timeline. |
2047 | + |
2048 | + Arguments: |
2049 | + id -- The user's screen name |
2050 | + count -- Number of tweets to get |
2051 | + since -- Time to get tweets since |
2052 | + |
2053 | Returns: |
2054 | - A list of gwibber compatible objects which have been parsed by _profile() |
2055 | + A list of Gwibber compatible objects which have been parsed by _profile(). |
2056 | + |
2057 | """ |
2058 | profiles = [self.profile(id)] or [] |
2059 | messages = self._get("statuses/user_timeline.json", id=id, include_entities=1, count=count, since_id=since) or [] |
This looks good, thanks!