3
# To access twitter with OAuth, you need to first obtain:
4
# consumer key, consumer secret, access token, access token secret
7
# 2. Go to https://dev.twitter.com/apps/new and fill the form
8
# - Application Type should be Client
9
# - Default Access Type must be Read and Write
10
# 3. Consumer key and secret are here: https://dev.twitter.com/apps
11
# 4. Access token and secret are in the My Access Token menu
14
''' hack to setup django environment START '''
18
from django.core.management import setup_environ
19
setup_environ(settings)
20
''' hack to setup django environment END '''
22
from oneliners.models import OneLiner
23
from oneliners.views import tweet
28
consumer_key = settings.TWITTER.get('consumer_key')
29
consumer_secret = settings.TWITTER.get('consumer_secret')
30
access_token = settings.TWITTER.get('access_token')
31
access_token_secret = settings.TWITTER.get('access_token_secret')
34
consumer_secret = None
36
access_token_secret = None
38
if __name__ == '__main__':
39
parser = optparse.OptionParser()
40
parser.set_usage('%prog [options]')
41
parser.set_description('Tweet specified one-liners by @bashoneliners')
43
parser.add_option('--pk', '--id', help='The pk/id of the OneLiner to tweet', type=int, action='append')
44
parser.add_option('--recent', help='List recent OneLiners, do not tweet', action='store_true', default=False)
45
parser.add_option('--send', help='Send tweets', action='store_true', default=False)
47
(options, args) = parser.parse_args()
49
if not (consumer_key and consumer_secret and access_token and access_token_secret):
51
print 'Error: Consumer Key is required!'
52
if not consumer_secret:
53
print 'Error: Consumer Secret is required!'
55
print 'Error: Access Token is required!'
56
if not access_token_secret:
57
print 'Error: Access Token Secret is required!'
62
for oneliner in OneLiner.recent()[:10]:
64
print oneliner.summary
71
oneliner = OneLiner.objects.get(pk=pk)
74
print tweet(oneliner, force=True)
76
print tweet(oneliner, force=True, test=True)