-
-
Save nicokruger/2131813 to your computer and use it in GitHub Desktop.
Create an 'everyone' list with everyone you're currently following.
This file contains hidden or 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
#!/usr/bin/python2 | |
import warnings | |
warnings.simplefilter('ignore', DeprecationWarning) | |
import httplib2, urllib, time | |
from urllib import urlencode | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
import sys | |
USERNAME, PASSWORD = sys.argv[1],sys.argv[2] | |
FRIENDS = "http://api.twitter.com/1/friends/ids.json" | |
h = httplib2.Http() | |
h.add_credentials(USERNAME, PASSWORD, 'api.twitter.com') | |
# make list - TODO check for existing list and update that | |
data = dict(name="everyone", description="everyone I follow") | |
headers, body = h.request( | |
"http://api.twitter.com/1/%s/lists.json" % USERNAME, "POST", urlencode(data) | |
) | |
list_info = json.loads(body) | |
print(list_info) | |
list_id = list_info['id'] | |
print("Created 'everyone' list with id '%s'" % list_id) | |
# fetch friends | |
headers, body = h.request( | |
FRIENDS, method='GET' | |
) | |
friend_ids = json.loads(body) | |
for id in friend_ids: | |
data = dict(list_id=list_id, id=id) | |
headers, body = h.request( | |
"http://api.twitter.com/1/%s/%s/members.json" % (USERNAME, list_id), "POST", urlencode(data) | |
) | |
user_info = json.loads(body) | |
print("Added user id %s" % id) | |
# TODO remove users no longer followed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment