0

Using Van Ling script on how to get a users url I adapted it and found two things I was looking for, one was to know the number of followers a certain screen name had so I used 'followers_count' instead of 'profile_image-url'

I also wanted more than the number of followers, I also wanted the day the account was created so I added a new details line 'created_at'

I also wanted more, I wanted this information for more than one account

This is where I need your help, I want details for more than one screen name

Below is the script I did and it works for one screen name so I hope you can make use of it, but When I ran it it only gave information on the followers and creation date for screen name No2

Thank you ..........................................

#!/home3/master/bin/python
import sys
sys.path.insert(1,'/home3/master/lib/python2.6/site-packages')

from twython import Twython

APP_KEY = 'appkey'
APP_SECRET = 'appsecret'
OAUTH_TOKEN = 'OToken'
OAUTH_TOKEN_SECRET = 'OTokenSecret'

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

details = twitter.show_user(screen_name='No1')
details = twitter.show_user(screen_name='No2')

print "content-type: text/html;charset=utf-8"

print"<html><head></head><body>"
print (details['followers_count']) #No of followers
print (details['created_at'])# Account creation date

1 Answers1

0

this is because you save screen_name='No1' to details, and then save screen_name='No2' to details, which will overwrite the user_details for the 'No1'.

You can either save the users to two different variables like this.

details_no1 = twitter.show_user(screen_name='No1')
details_no2 = twitter.show_user(screen_name='No2')

print "content-type: text/html;charset=utf-8"
print"<html><head></head><body>"

# Screen name 'No1'
print (details_no1['screen_name']) # Screen name
print (details_no1['followers_count']) #No of followers
print (details_no1['created_at'])# Account creation date

# Screen name 'No2'
print (details_no2['screen_name']) # Screen name
print (details_no2['followers_count']) #No of followers
print (details_no2['created_at'])# Account creation date

or if you want this information for a number of accounts you could save all the details to an array and then iterate it like this.

screen_names = ['No1', 'No2']

print"<html><head></head><body>"

for screen_name in screen_names:
    details = twitter.show_user(screen_name=screen_name)
    print (details['screen_name']) # Screen name
    print (details['followers_count']) #No of followers
    print (details['created_at'])# Account creation date
oyvindym
  • 352
  • 1
  • 2
  • 15