From 3911011d202ae4f7f6f5021e550fa449b9f3574b Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Sat, 17 May 2014 13:08:34 +1000 Subject: [PATCH] CLI script to display a tweet and the poster of that tweet using the tweet status ID through command line arguments. --- examples/show_status.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/show_status.py diff --git a/examples/show_status.py b/examples/show_status.py new file mode 100644 index 0000000..b4da77f --- /dev/null +++ b/examples/show_status.py @@ -0,0 +1,23 @@ +from twython import Twython, TwythonError + +# Optionally accept user data from the command line (or elsewhere). +# +# Usage: show_status.py 463604849372704768 + +import sys + +if len(sys.argv) >= 2: + target = sys.argv[1] +else: + target = raw_input("ID number of tweet to fetch: ") # For Python 3.x use: target = input("ID number of tweet to fetch: ") + +# Requires Authentication as of Twitter API v1.1 +twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) + +try: + tweet = twitter.show_status(id=twid) + print(tweet["user"]["name"]+" ("+tweet["user"]["screen_name"]+"): "+tweet["text"]) +except TwythonError as e: + print(e) + +# This will print: Name (screen name): the content of the tweet selected.