39
39
def tweet(oneliner, test=False, consumer_key=None, consumer_secret=None, access_token=None, access_token_secret=None):
40
if oneliner.is_published:
42
import tweepy # 3rd party lib, install with: easy_install tweepy
44
if consumer_key is None:
45
consumer_key = settings.TWITTER.get('consumer_key')
46
if consumer_secret is None:
47
consumer_secret = settings.TWITTER.get('consumer_secret')
48
if access_token is None:
49
access_token = settings.TWITTER.get('access_token')
50
if access_token_secret is None:
51
access_token_secret = settings.TWITTER.get('access_token_secret')
53
# set up credentials to use Twitter api.
54
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
55
auth.set_access_token(access_token, access_token_secret)
56
api = tweepy.API(auth)
58
tweetmsg = 'http://bashoneliners.com/main/oneliner/%d %s: %s # posted by %s' % (
62
oneliner.user.username,
64
if len(tweetmsg) > 161:
65
tweetmsg = tweetmsg[:157] + ' ...'
72
return api.update_status(tweetmsg)
40
if not oneliner.was_tweeted:
41
if oneliner.is_published:
43
import tweepy # 3rd party lib, install with: easy_install tweepy
45
if consumer_key is None:
46
consumer_key = settings.TWITTER.get('consumer_key')
47
if consumer_secret is None:
48
consumer_secret = settings.TWITTER.get('consumer_secret')
49
if access_token is None:
50
access_token = settings.TWITTER.get('access_token')
51
if access_token_secret is None:
52
access_token_secret = settings.TWITTER.get('access_token_secret')
54
# set up credentials to use Twitter api.
55
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
56
auth.set_access_token(access_token, access_token_secret)
57
api = tweepy.API(auth)
59
tweetmsg = 'http://bashoneliners.com/main/oneliner/%d %s: %s # posted by %s' % (
63
oneliner.user.username,
65
if len(tweetmsg) > 160:
66
tweetmsg = tweetmsg[:156] + ' ...'
73
oneliner.was_tweeted = True
75
return api.update_status(tweetmsg)
77
80
''' url handlers '''