Im working on learning some python and I wanted to write a script that would pull my followers usernames from my twitter and save it to a file.
The script comes from this website https://www.silkstream.net/blog/2014/06/playing-with-followers-with-twython-csv.html
the code i've typed up is below
from twython import Twython
import datetime
app_key = ""
app_secret = ""
oauth_token = ""
oauth_token_secret = ""
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
#twitter.update_status(status = "Testing a script dont mind this tweet")
followers = []
datestamp = datetime.datetime.now().strftime("%Y-%m-%d")
username = input("what is your username: ")
next_cursor = -1
while(next_cursor):
get_followers = twitter.get_followers_list(screen_name=username,count=200,cursor=next_cursor)
for followers in get_followers["users"]:
followers.append(follower["screen_name"].encode("utf-8"))
next_cursor = get_followers["next_cursor"]
followers_text = open(username+"-"+datestamp+".txt","a")
followers_text.write("%s has %s followers (%s)):" % (str(username),str(len(followers)),str(datestamp))+"".join(followers))
followers_text.close()
when I run the program I get this output
File "first.py", line 19, in <module>
followers.append(follower["screen_name"].encode("utf-8"))
AttributeError: 'dict' object has no attribute 'append'
If I comment out line 19 it actually runs but i get this weird output in the saved file
idid_strnamescreen_namelocationdescriptionurlentitiesprotectedfollowers_countfriends_countlisted_countcreated_atfavourites_countutc_offsettime_zonegeo_enabledverifiedstatuses_countlangstatuscontributors_enabledis_translatoris_translation_enabledprofile_background_colorprofile_background_image_urlprofile_background_image_url_httpsprofile_background_tileprofile_image_urlprofile_image_url_httpsprofile_banner_urlprofile_link_colorprofile_sidebar_border_colorprofile_sidebar_fill_colorprofile_text_colorprofile_use_background_imagehas_extended_profiledefault_profiledefault_profile_imagefollowinglive_followingfollow_request_sentnotificationsmutingblockingblocked_bytranslator_type
it looks like it thinks something is a dictionary(or at least that's my guess) but I don't have any in there do I?