Skip to content

Instantly share code, notes, and snippets.

@perpetual-hydrofoil
Last active September 5, 2016 16:42
Show Gist options
  • Save perpetual-hydrofoil/2ba663e3f9b3417a73ef80d4f5e68124 to your computer and use it in GitHub Desktop.
Save perpetual-hydrofoil/2ba663e3f9b3417a73ef80d4f5e68124 to your computer and use it in GitHub Desktop.
Single tweet CLI in 8 LoC
#! /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