forked from oh-moore/followpie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollowpie.py
212 lines (185 loc) · 7.43 KB
/
followpie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# DO NOT TOUCH THESE THREE CONST VARIABLES
POPULAR = 1
LIKE = 2
LIKE_FOLLOW = 3
#Choose the tag you want to like based on, keep the word in double quotes, do not put a # sign in front of the tag
TAGS = ["beach", "lolcats", "kerry", "tree"]
#IF YOU WANT THE ACTION TO FOLLOW OR LIKE SOMEONE BASED ON THE CHOSEN TAG CHANGE IT TO EITHER
# ACTION=POPULAR - Popular follows people who have liked an image on the popular page (this means they are active users)
# ACTION=LIKE
# ACTION=LIKE_FOLLOW
ACTION = LIKE_FOLLOW
#CHANGE THE NUMBER OF LIKES OR FOLLOWS YOU WANT TO OCCUR, e.g. NO MORE THEN 100 is the current setting
MAX_COUNT = 100
#MAX seconds is the number of seconds to randomly wait between doing your next follow or like (this helps to avoid acting like a crazy spam bot)
MAX_SECS = 2
#Hit the URL below, the returned GET request will give you an auth token from Instagram.
#
#THE AUTH TOKEN IS THE KEY THAT YOU GET WHEN YOU SIGN IN WITH THE FOLLOWING CLIENT URL.
#DOES NOT NEED TO CHANGE UNLESS AUTH TOKEN EXPIRES
#
#
# https://api.instagram.com/oauth/authorize/?client_id=1627c123e3fc481791e0d6be16ff57a0&redirect_uri=http://yoururl.com&response_type=token&display=touch&scope=likes+relationships
#
auth_token = "2085179.1627c12.939ae81957124868a718c693e94f8218"
client_id = '1627c123e3fc481791e0d6be16ff57a0'
######DO NOT TOUCH ANYTHING UNDER HERE UNLESS YOU KNOW WHAT YOU ARE DOING, DANGER DANGER, SERIOUS PROBLEMS IF YOU TOUCH ###########
print "FOLLOW PIE BEGINS - GRAB A SLICE AND SIT BACK"
print ""
print "The script will now proceed to follow and like users"
print ""
print ""
import time, random
import urllib,json,urllib2
user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7'
headers = { 'User-Agent' : user_agent,
"Content-type": "application/x-www-form-urlencoded"
}
likedDict = {}
def likePicture(pictureId):
liked = 0
try:
urlLike = "https://api.instagram.com/v1/media/%s/likes"
values = {'access_token' : auth_token,
'client_id' : client_id}
newLike = urlLike % (pictureId)
print newLike
data = urllib.urlencode(values)
req = urllib2.Request(newLike,data,headers)
response = urllib2.urlopen(req)
result = response.read()
dataObj = json.loads(result)
liked = 1
except Exception, e:
print e
return liked
def followUser(userId):
followed=0
followUrl = "https://api.instagram.com/v1/users/%s/relationship?action=allow"
values = {'access_token' : auth_token,
'action' : 'follow',
'client_id' : client_id}
try:
newFollow = followUrl % (userId)
print newFollow
data = urllib.urlencode(values)
req = urllib2.Request(newFollow,data,headers)
response = urllib2.urlopen(req)
result = response.read()
print result
dataObj = json.loads(result);
followed = 1
except Exception, e:
print e
return followed
def likeAndFollowUser(userId):
numLikesFollows=0
urlUserMedia = "https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s" % (userId,auth_token)
values = {
'client_id' : client_id}
try:
print urlUserMedia
data = urllib.urlencode(values)
req = urllib2.Request(urlUserMedia,None,headers)
response = urllib2.urlopen(req)
result = response.read()
dataObj = json.loads(result);
picsToLike = random.randint(1, 3)
print "Liking %s pics for user %s" % (picsToLike, userId)
countPicViews=0
for picture in dataObj['data']:
print "Liking picture %s " % picture['id']
likePicture(picture['id'])
countPicViews = countPicViews+1
numLikesFollows = numLikesFollows+1
if(countPicViews == picsToLike):
break
followed=1
except Exception, e:
print e
followUser(userId)
return numLikesFollows
if(ACTION == LIKE or ACTION == LIKE_FOLLOW):
def likeUsers(max_results,max_id,tag,c,fllw):
urlFindLike="https://api.instagram.com/v1/tags/%s/media/recent?client_id=1627c123e3fc481791e0d6be16ff57a0&access_token=%s" % (tag,auth_token);
urlLike="https://api.instagram.com/v1/media/%s/likes"
values = {'access_token' : auth_token,
'client_id' : client_id,
'max_id' : max_id}
f = urllib.urlopen(urlFindLike)
dataObj = json.loads(f.read())
f.close()
numResults = len(dataObj['data'])
pictureId=0
for likeObj in dataObj['data']:
print ''
pictureId = likeObj['id']
paginationId = dataObj["pagination"]['next_max_id']
user = likeObj['user']
userId = user['id']
try:
numLikes = likedDict[pictureId]
numLikes = numLikes+1
likedDict[pictureId] = numLikes
except:
numLikes = 1
likedDict[pictureId] = numLikes
try:
result = likePicture(pictureId)
if(ACTION==LIKE_FOLLOW):
print "Following user %s" % userId
fresult=followUser(userId)
fllw=fllw+fresult
c=c+result
seconds=random.randint(1, MAX_SECS)
time.sleep(seconds)
if(c%10==0):
print "Liked %s: %s" % (tag,c)
if(fllw%10==0 and fllw!=0):
print "Followed %s: %s" % (tag,fllw)
if(c==max_results):
break
except Exception, e:
print e
if(c!=max_results):
likeUsers(max_results,paginationId,tag,c,fllw)
return c,fllw
print ''
for tag in TAGS:
c=0
f=0
c,f=likeUsers(MAX_COUNT,0,tag,c,f)
print "Liked %s: Followed %s: for tag %s" %(c,f,tag)
for likes in likedDict:
print "%s = %s" % (likes, likedDict[likes])
elif(ACTION==POPULAR):
urlPopular="https://api.instagram.com/v1/media/popular?client_id=1627c123e3fc481791e0d6be16ff57a0";
f = urllib.urlopen(urlPopular)
dataObj=json.loads(f.read())
f.close()
i=0
c=0
l=0
for obj in dataObj['data']:
for comment in obj['likes']['data']:
myid=comment['id']
try:
result=likeAndFollowUser(myid)
if(result>0):
c=c+1
l=l+result
if(c%10==0):
print "Followed %s" % c
seconds=random.randint(1, MAX_SECS)
time.sleep(seconds)
except Exception, e:
print e
if(c==MAX_COUNT):
break
if(c==MAX_COUNT):
break
""
print ""
print "Followed %s" % (c);
print "Liked %s" % (l);
print "FOLLOW PIE ENDS - HAPPY DIGESTING"