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' ]
Links
account_info on github.
Nice write-up, thanks René!
ReplyDeleteThat's actually the correct most recent Tweet from the @twitterapi account (you'll have to switch to the Tweets & Replies tab on the user profile page to see that on the web site). It is generally a low-volume account used for API announcements.
birdy is a nice library for Python, there is also tweepy which is pretty popular as well.
Thanks for sharing with the community!
Thanks a lot for your feedback, Andy. I definitely should take a look at tweepy another day.
Delete