Friday, 18 November 2022

Por si las moscas

Aprovechando que puedo usar la API de twitter para el bot del calendario, he creado un programita para descargarme las listas de seguidos y seguidores en twitter (muy modestas). Nunca se sabe. 

def write_file(tweepy_function, screen_name, file_name):
    #https://stackoverflow.com/questions/52450621/get-list-of-followers-and-following-for-group-of-users-tweepy
    csvFile = open(file_name+'.csv', 'w')
    csvWriter = csv.writer(csvFile)
    c = 1
    for page in tweepy.Cursor(tweepy_function, screen_name=screen_name, count=200).pages(50):
        for user in page:
            csvWriter.writerow([user.screen_name, user.id, user.url, user.location, user.followers_count, user.friends_count, user.description.encode('utf-8')])
            print(c, ',', user.name, ', @'+user.screen_name, user.url)
            c+=1
    csvFile.close()
    return None

def main():
    api = get_tweepy_api() #tweepy.API(auth)
    screen_name = "your_handle_without_@"
    write_file(api.get_followers, screen_name, 'followers')
    write_file(api.get_friends, screen_name, 'following')

No comments: