Last active
September 5, 2016 16:42
-
-
Save perpetual-hydrofoil/2ba663e3f9b3417a73ef80d4f5e68124 to your computer and use it in GitHub Desktop.
Single tweet CLI in 8 LoC
This file contains 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/env python | |
# call with (newlines respected inside quotes) | |
# tweet.py "my | |
# tweet" | |
# or | |
# echo "my tweet" | tweet.py | |
import tweepy | |
import sys | |
import requests | |
# remember to set appropriate consumer_*, api_* etc: | |
# authenticate | |
auth = tweepy.auth.OAuthHandler( | |
consumer_key=consumer_key, | |
consumer_secret=consumer_secret) | |
auth.set_access_token(api_token, api_secret) | |
# prepare tweet | |
to_tweet = " ".join(sys.argv[1:]) | |
if not to_tweet: to_tweet = sys.stdin.read() | |
# tweet it: | |
tweepy.API(auth_handler=auth).update_status(to_tweet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment