annotate bitsytweet/__init__.py @ 4:ed3c5f7ba348

print to stderr instead of dying on exceptions
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 26 Jul 2010 07:08:37 -0700
parents 50f77774a20a
children da132a64926e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
4
ed3c5f7ba348 print to stderr instead of dying on exceptions
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
2 BitsyTweet - tweet your bitsyblog entries (horrid, I know)
0
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
4
ed3c5f7ba348 print to stderr instead of dying on exceptions
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
5 import sys
0
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 import twitter
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 class BitsyTweet(object):
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
3
50f77774a20a made tweeting work
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
10 def __init__(self, bitsyblog, username, password):
2
f0ee545bba37 more stubbing of API
Jeff Hammel <jhammel@mozilla.com>
parents: 1
diff changeset
11 self.bitsyblog = bitsyblog
0
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 self.username = username
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 self.password = password
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 self.api = twitter.Api(username=self.username, password=self.password)
56a9fb9ad9b4 initial commit of bitsytweet (not yet functional)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15
3
50f77774a20a made tweeting work
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
16 def __call__(self, blog_entry, url):
2
f0ee545bba37 more stubbing of API
Jeff Hammel <jhammel@mozilla.com>
parents: 1
diff changeset
17 if blog_entry.privacy == 'public': # only tweet public blogs
3
50f77774a20a made tweeting work
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
18 tweet = '%s : %s' % (blog_entry.snippet(), url)
4
ed3c5f7ba348 print to stderr instead of dying on exceptions
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
19 try:
ed3c5f7ba348 print to stderr instead of dying on exceptions
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
20 self.api.PostUpdate(tweet)
ed3c5f7ba348 print to stderr instead of dying on exceptions
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
21 except Exception, e:
ed3c5f7ba348 print to stderr instead of dying on exceptions
Jeff Hammel <jhammel@mozilla.com>
parents: 3
diff changeset
22 print >> sys.stderr, "Couldn't tweet %s (%s)" % (url, e)