Last active
December 7, 2017 08:41
-
-
Save ferranpons/1815fc02ffb744e7e06ccdabf42363da to your computer and use it in GitHub Desktop.
Gist that publish a Twitter update (tweet) on the given account (key, secret, access token, access token secret) using Tweepy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys, getopt | |
import tweepy | |
def main(argv): | |
consumer_key = '' | |
consumer_secret = '' | |
access_token = '' | |
access_token_secret = '' | |
update_text = '' | |
try: | |
opts, args = getopt.getopt(argv,"h:k:s:a:t:u:",["consumer-key=","consumer-secret=","access-token=","access-token-secret=","update-text"]) | |
except getopt.GetoptError: | |
print 'test.py -k <consumer_key> -s <consumer_secret> -a <access_token> -t <access_token_secret> -u <update_text>' | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print 'test.py -k <consumer_key> -s <consumer_secret> -a <access_token> -t <access_token_secret> -u <update_text>' | |
sys.exit() | |
elif opt in ("-k", "--consumer-key"): | |
consumer_key = arg | |
elif opt in ("-s", "--consumer-secret"): | |
consumer_secret = arg | |
elif opt in ("-a", "--access-token"): | |
access_token = arg | |
elif opt in ("-t", "--access-token-secret"): | |
access_token_secret = arg | |
elif opt in ("-u", "--update-text"): | |
update_text = arg | |
if consumer_key != "" and consumer_secret != "" and access_token != "" and access_token_secret != "" and update_text != "": | |
print 'Tweeting...' | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
api.update_status(update_text) | |
print 'tweet done' | |
else: | |
print 'Tweet not performed. Please provide all the values needed.' | |
sys.exit() | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment