Skip to content

Instantly share code, notes, and snippets.

@fpom
Created February 12, 2016 09:27
Show Gist options
  • Save fpom/229cbb7e8a5aa4dbcf60 to your computer and use it in GitHub Desktop.
Save fpom/229cbb7e8a5aa4dbcf60 to your computer and use it in GitHub Desktop.
Follow your Twitter followers
import os.path, codecs
import twitter
api = twitter.Api(consumer_key="YOUR USER ID HERE",
consumer_secret="YOUR SECRET KEY HERE",
access_token_key="YOUR TOKEN KEY HERE",
access_token_secret="YOUR SECRET TOKEN HERE")
if os.path.isfile("followers.dump") :
with codecs.open("followers.dump", encoding="utf-8") as infile :
old = dict(line.strip().split(" ", 1) for line in infile if line.strip())
else :
old = {}
new = dict((f.screen_name, f.name) for f in api.GetFollowers())
enter = set(new) - set(old)
leave = set(old) - set(new)
for name in enter :
print "+", name, new[name]
for name in leave :
print "-", name, old[name]
with codecs.open("followers.dump", "w", encoding="utf-8") as outfile :
for item in new.items() :
outfile.write(" ".join(item) + "\n")
print("= %s followers (%s new, %s left)" % (len(new), len(enter), len(leave)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment