Skip to content

Instantly share code, notes, and snippets.

@gabalese
Created June 3, 2013 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabalese/5698842 to your computer and use it in GitHub Desktop.
Save gabalese/5698842 to your computer and use it in GitHub Desktop.
Quick and dirty script to post a tweet from the CLI interface. Requires twitter library.
#! /usr/bin/env python3
from twitter import *
import os, sys
CONSUMER_KEY = <your_consumer_key>
CONSUMER_SECRET <your_consumer_secret_key>
MY_TWITTER_CREDS = os.path.expanduser('~/.token_cache')
if not os.path.exists(MY_TWITTER_CREDS):
try:
oauth_dance(<your_app_name>, CONSUMER_KEY, CONSUMER_SECRET, MY_TWITTER_CREDS)
except Exception as e:
print("IMPOSSIBILE AUTENTICARE.")
print(e)
sys.exit(2)
oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS)
twitter = Twitter(auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
if __name__ == "__main__":
if len(sys.argv) < 2:
print(twitter.statuses.home_timeline())
else:
twitter.statuses.update(status=sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment