-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwit_post.py
27 lines (23 loc) · 971 Bytes
/
twit_post.py
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
import twitter
import sys
import ConfigParser
#See twit_post.conf for an example configuration file
config_file = "Your configuration file (use full path if not in local directory)"
def post_status(account, status):
#Read config file for account data
config = ConfigParser.RawConfigParser()
config.read(config_file)
consumer_key = config.get('defaults', 'consumer_key')
consumer_secret = config.get('defaults', 'consumer_secret')
access_token_key = config.get(account, 'access_token_key')
access_token_secret = config.get(account, 'access_token_secret')
try:
api = twitter.Api(consumer_key = consumer_key, consumer_secret = consumer_secret, access_token_key = access_token_key, access_token_secret = access_token_secret)
print status
print 'posting to Twitter...'
result = api.PostUpdate(status)
print ' post successful!\n\n'
except twitter.TwitterError:
print ' post failed'
if __name__ == "__main__":
post_status(sys.argv[1], sys.argv[2])