[PYTHON] Manipulating Twitter lists

https://dev.twitter.com/docs/api/1.1/get/lists/members

List reference

#Get a list of users and output the number of registered users

#t is a twitter class instance
hoge = t.lists.list(user_id='user_id')

for h in hoge:
    print(h['name'] + ':' + h['id_str'])
    cursor = '-1' 
    count = 0
    while cursor != '0':
        #cursor=-1 the first "page."
        tl = t.lists.members(list_id=h['id_str'],cursor=cursor)
        count += len(tl['users'])
        cursor = tl['next_cursor_str'] #If there is no next page, 0 is entered
    print(count)

Recommended Posts

Manipulating Twitter lists
Manipulating Python character lists (arrays)