Created
February 12, 2016 09:27
-
-
Save fpom/229cbb7e8a5aa4dbcf60 to your computer and use it in GitHub Desktop.
Follow your Twitter followers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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