· 9 years ago · Sep 11, 2016, 11:40 AM
1from twitter import Twitter, OAuth, TwitterHTTPError
2import os, time
3
4#login details
5OAUTH_TOKEN = "1670737290-zZDMnuIFzddoueFInEjZAGHWhj5hLLAn4yAbVX9"
6OAUTH_SECRET = "BA3VMXyUP4VXSgZGirEKikcTMv98588avJqjTmiD6XZ5q"
7CONSUMER_KEY = "qgpqvqsXozAMrDQJzApHLskHS"
8CONSUMER_SECRET = "mWVJd40WnoLs5h1LtUWR43ufpth3RMTIMKYSNTKennEUEzsuMY"
9TWITTER_HANDLE = "ythoooooo"
10
11#account to follow
12page = "dory"
13
14
15# put the full path and file name of the file you want to store your "already followed"
16# list in
17ALREADY_FOLLOWED_FILE = "already-followed.csv"
18
19t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
20 CONSUMER_KEY, CONSUMER_SECRET))
21
22def get_do_not_follow_list():
23 """
24 Returns list of users the bot has already followed.
25 """
26
27 # make sure the "already followed" file exists
28 if not os.path.isfile(ALREADY_FOLLOWED_FILE):
29 with open(ALREADY_FOLLOWED_FILE, "w") as out_file:
30 out_file.write("")
31
32 # read in the list of user IDs that the bot has already followed in the
33 # past
34 do_not_follow = set()
35 dnf_list = []
36 with open(ALREADY_FOLLOWED_FILE) as in_file:
37 for line in in_file:
38 dnf_list.append(int(line))
39
40 do_not_follow.update(set(dnf_list))
41 del dnf_list
42
43 return do_not_follow
44
45def auto_follow_followers_for_user(user_screen_name, count=100):
46 """
47 Follows the followers of a user
48 """
49 following = set(t.friends.ids(screen_name=TWITTER_HANDLE)["ids"])
50 followers_for_user = set(t.followers.ids(screen_name=user_screen_name)["ids"][:count]);
51 do_not_follow = get_do_not_follow_list()
52
53 for user_id in followers_for_user:
54 try:
55 if (user_id not in following and
56 user_id not in do_not_follow):
57
58 t.friendships.create(user_id=user_id, follow=False)
59
60 f = open("already-followed.csv","a")
61 f.write(str(user_id) + "\n")
62
63 print("followed %s" % user_id)
64 time.sleep(90)
65
66 except TwitterHTTPError as e:
67 print("error: %s" % (str(e)))
68
69
70
71auto_follow_followers_for_user(page, count=50)
72
73'''
74var $btns = $(".follow-button")
75, to = 0;
76
77$.each($btns, function(i, x){
78 setTimeout(function(){
79 $(x).click();
80 }, to);
81
82 to += 50;
83});
84'''