├── creds.txt ├── README.md └── goggles.py /creds.txt: -------------------------------------------------------------------------------- 1 | {'consumer_key': "", 2 | 'consumer_secret': "", 3 | 'access_token': "", 4 | 'access_token_secret': "", 5 | 'myID': "", 6 | 'myName': ""} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # twitter goggles v1.1 2 | see twitter as someone else sees it, by picking someone you follow at random and creating a list populated with everyone *they* follow. 3 | 4 | ### installation 5 | requirements: python 2.7x, tweepy, valid twitter API credentials 6 | 7 | ```pip install tweepy``` 8 | 9 | then you'll need to visit https://apps.twitter.com/ to create an application (if you don't have one already) and get your API credentials. here's a guide that explains how to do that: http://iag.me/socialmedia/how-to-create-a-twitter-app-in-8-easy-steps/ 10 | 11 | note the following information: 12 | 13 | ```Consumer Key``` 14 | 15 | ```Consumer Secret``` 16 | 17 | ```Access Token``` 18 | 19 | ```Access Token Secret``` 20 | 21 | ```Owner ID``` 22 | 23 | paste each of those (and your twitter handle) into its appropriate field in creds.txt, and you should be able to run the script. 24 | 25 | ### running the script 26 | ```python goggles.py``` 27 | 28 | ### generating another list 29 | edit goggles.py line 70 and change the name 'goggles' to a different name 30 | 31 | ### deleting a list 32 | delete lists from inside twitter at https://twitter.com/yourname/lists 33 | 34 | ### release notes 35 | 36 | v1.1 37 | --- 38 | lists go up to 5,000 now (@hugovk) 39 | 40 | list opens in browser when complete (@hugovk) 41 | 42 | lists are now private by default 43 | 44 | added user handle to creds.txt 45 | 46 | 47 | v1.0 48 | --- 49 | initial release -------------------------------------------------------------------------------- /goggles.py: -------------------------------------------------------------------------------- 1 | import tweepy 2 | from tweepy import OAuthHandler 3 | import random 4 | import time 5 | import webbrowser 6 | 7 | # 8 | # this function returns a connection to the twitter API, using credentials loaded from creds.txt 9 | # 10 | def getAPI(creds): 11 | auth = OAuthHandler(creds['consumer_key'], creds['consumer_secret']) 12 | auth.set_access_token(creds['access_token'], creds['access_token_secret']) 13 | 14 | api = tweepy.API(auth) 15 | return api 16 | 17 | # start by loading twitter API credentials from creds.txt 18 | creds = {} 19 | with open('creds.txt', 'r') as file: 20 | creds = eval(file.read()) 21 | 22 | file.close() 23 | 24 | # use our credentials to get an API connection 25 | api = getAPI(creds) 26 | 27 | # grab our user ID 28 | myID = creds['myID'] 29 | 30 | # grab the list of everyone we follow 31 | current = api.friends_ids() 32 | 33 | # find someone who also follows us back 34 | mutual = False 35 | while not mutual: 36 | candidateID = random.choice(current) 37 | 38 | candidate = api.get_user(candidateID) 39 | relationship = api.show_friendship(source_id=myID, target_id=candidateID) 40 | 41 | if relationship[0].followed_by: 42 | mutual = True 43 | 44 | # grab their screen name 45 | handle = candidate.screen_name 46 | 47 | # tell us who it is already 48 | print "creating " + handle + " goggles" 49 | 50 | # grab the list of everyone they're following 51 | newids = [] 52 | counter = 0 53 | 54 | for page in tweepy.Cursor(api.friends_ids, screen_name=handle).pages(): 55 | print "grabbing page" 56 | newids.extend(page) 57 | if counter != 0: 58 | time.sleep(30) 59 | counter += 1 60 | 61 | # generate the list's description 62 | desc = "following " + handle + "'s timeline" 63 | 64 | # the name of our list. change this to make a new list! 65 | listName = "goggles" 66 | 67 | # create a new list called 'goggles' with the generated description 68 | goggles = api.create_list(name=listName, mode='public', description=desc) 69 | 70 | # populate list; twitter lists are limited to 5,000 members, 71 | # so grab a random sampling if necessary 72 | if len(newids) <= 5000: 73 | for x, pal in list(enumerate(newids)): 74 | print "adding " + str(x) 75 | api.add_list_member(slug=listName, id=pal, owner_screen_name=myID) 76 | else: 77 | 78 | random.shuffle(newids) 79 | for x, pal in list(enumerate(newids[0:5000])): 80 | print "adding " + str(x) 81 | api.add_list_member(slug=listName, id=pal, owner_screen_name=myID) 82 | 83 | # we did it 84 | print "complete" 85 | 86 | url = "https://twitter.com" + goggles.uri 87 | print url 88 | webbrowser.open(url, new=2) # 2 = open in a new tab, if possible 89 | --------------------------------------------------------------------------------