My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from restful_lib import Connection, ConnectionError
from microblog_exceptions import MicroBlogMsgLimitExceeded

class FailWhale(Exception):
def __str__(self):
return "Oh noes, the failwhale cometh!"

TWITTER_ENDPOINT = "http://twitter.com/statuses/update.json"

class Twitter(object):
def __init__(self, username,password):
self._conn = Connection(TWITTER_ENDPOINT, username, password)

def post(self, message, clip_length=False):
if isinstance(message, list):
# Default to a joining up the list of words with a space
message = " ".join(message)

if len(message)>140:
if clip_length:
message = message[:140]
else:
raise MicroBlogMsgLimitExceeded

resp = c.request_post("", args={"status":message})

if resp.get('headers').get('status') not in ["200", 200, "204", 204]:
raise FailWhale

Change log

r12 by bosteen on Jul 9, 2008   Diff
* FIX - POST params are now correctly
handed

* Added example wrapper library for
posting to twitter.

Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 937 bytes, 28 lines
Powered by Google Project Hosting