Showing posts with label birdy. Show all posts
Showing posts with label birdy. Show all posts

Wednesday, January 20, 2016

Using birdy to tweet a message

birdy makes it easy to tweet a message:

u:\20-birdy> tweet.py "Hello World!"

Here's the script (tweet.py):

import os import sys from birdy.twitter import UserClient if len(sys.argv) < 2: print "specify text to tweet" sys.exit() tweet_text = sys.argv[1] tw = UserClient(os.environ['TWITTER_CONSUMER_KEY' ], os.environ['TWITTER_CONSUMER_SECRET' ], os.environ['TWITTER_ACCESS_TOKEN' ], os.environ['TWITTER_ACCESS_TOKEN_SECRET']) tw.api.statuses.update.post(status = tweet_text)
Experimenting with the twitter API client birdy

tweet.py

birdy

Experimenting with the twitter API client birdy

I stumbled upon the twitter API client birdy whose description reads a super awesome Twitter API client for Python.

Of course, inquiring minds want to know, so I wrote a little script (account_info.py). The script takes one argument: the name of a twitter account. In the following screenshot, I read some account data for the account twitterapi:

For example, the script reports that twitterapi has 5.3 million followers, but follows only 48 other accounts.

The script is also able to read the current status. For a reason I don't understand, the status for twitterapi seems always to be "@TheNiceBot aww thanks, you're lovely too! :-)". The status is correct, however, for other accounts.

Here's the script

import os import sys from birdy.twitter import UserClient if len(sys.argv) < 2: print "specify screen name" sys.exit() screen_name = sys.argv[1] tw = UserClient(os.environ['TWITTER_CONSUMER_KEY' ], os.environ['TWITTER_CONSUMER_SECRET' ], os.environ['TWITTER_ACCESS_TOKEN' ], os.environ['TWITTER_ACCESS_TOKEN_SECRET']) r = tw.api.users.show.get(screen_name=screen_name) profile_url=r.data['profile_background_image_url_https'] # for key, value in r.data.iteritems() : # print key status_id=str(r.data['status']['id_str']) print "" print "Current Status" print " of " + r.data['status']['created_at'] print " url=https://twiter.com/" + screen_name + "/status/" + status_id print "------------------------------------------------------" print r.data['status']['text'] print "--------------" print "" print "Name: " + r.data['name' ] print "Description: " + r.data['description' ] print "Followers: " + str(r.data['followers_count']) print "Following: " + str(r.data['friends_count' ]) print "Tweets: " + str(r.data['statuses_count' ]) print "Language: " + r.data['lang' ]
account_info on github.
Inueni's github repository birdy.