forked from cranklin/Instagram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webstagrambot.py
212 lines (176 loc) · 9.95 KB
/
webstagrambot.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
#!/usr/bin/python
'''
Cranklin's Instagram Bot v.1.0
==============================
Check www.cranklin.com for updates
This bot gets you more likes and followers on your Instagram account.
Requirements:
- python > 2.6 but < 3.0
- pycurl library
- web.stagram.com login prior to using the bot
Instructions:
- make sure you have the correct version of Python installed
- make sure you have the pycurl library installed
- log into web.stagram.com with your instagram account and approve the app
- edit between lines 42 and 52
- from the command line, run "python webstagram.py"
- enjoy!
v1.0 updates:
- added browser agent randomizer
- added optional sleep timer
- added optional hashtag limiter
- added a couple extra additions for some people experiencing SSL errors. (thanks Charlie)
*** thank you Nick, John, Max, Shahar, Charlie for the help
'''
import os
import pycurl
import cStringIO
import re
import random
import time
##### EDIT THESE BELOW
# your instagram username and password
username = "username"
password = "password"
#set a sleep timer between each like. Set value to 0 if you don't want it to sleep at all
sleeptimer = 5
#set a like limit per hashtag. Set value to 0 if you don't want a limit
hashtaglikelimit = 100
#your list of hashtags
hashtags = ["love","instagood","me","cute","photooftheday","tbt","instamood","iphonesia","picoftheday","igers","girl","beautiful","instadaily","tweegram","summer","instagramhub","follow","bestoftheday","iphoneonly","igdaily","happy","picstitch","webstagram","fashion","sky","nofilter","jj","followme","fun","smile","sun","pretty","instagramers","food","like","friends","lol","hair","nature","swag","onedirection","bored","funny","life","cool","beach","blue","dog","pink","art","hot","my","family","sunset","photo","versagram","instahub","amazing","statigram","girls","cat","awesome","throwbackthursday","repost","clouds","baby","red","music","party","black","instalove","night","textgram","followback","all_shots","jj_forum","igaddict","yummy","white","yum","bestfriend","green","school","likeforlike","eyes","sweet","instago","tagsforlikes","style","harrystyles","2012","foodporn","beauty","ignation","niallhoran","i","boy","nice","halloween","instacollage"]
##### NO NEED TO EDIT BELOW THIS LINE
browsers = ["IE ","Mozilla/","Gecko/","Opera/","Chrome/","Safari/"]
operatingsystems = ["Windows","Linux","OS X","compatible","Macintosh","Intel"]
def login():
try:
os.remove("pycookie.txt")
except:
pass
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://web.stagram.com")
c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
c.setopt(pycurl.WRITEFUNCTION, buf.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.ENCODING, "")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
useragent = random.choice(browsers) + str(random.randrange(1,9)) + "." + str(random.randrange(0,50)) + " (" + random.choice(operatingsystems) + "; " + random.choice(operatingsystems) + "; rv:" + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + ")"
c.setopt(pycurl.USERAGENT, useragent)
c.perform()
curlData = buf.getvalue()
buf.close()
clientid = re.findall(ur"href=\"https:\/\/api.instagram.com\/oauth\/authorize\/\?client_id=([a-z0-9]*)&redirect_uri=http:\/\/web.stagram.com\/&response_type=code&scope=likes\+comments\+relationships\">LOG IN",curlData)
instagramlink = re.findall(ur"href=\"([^\"]*)\">LOG IN",curlData)
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, instagramlink[0])
c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
c.setopt(pycurl.WRITEFUNCTION, buf.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.ENCODING, "")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
useragent = random.choice(browsers) + str(random.randrange(1,9)) + "." + str(random.randrange(0,50)) + " (" + random.choice(operatingsystems) + "; " + random.choice(operatingsystems) + "; rv:" + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + ")"
c.setopt(pycurl.USERAGENT, useragent)
c.perform()
curlData = buf.getvalue()
buf.close()
postaction = re.findall(ur"action=\"([^\"]*)\"",curlData)
csrfmiddlewaretoken = re.findall(ur"name=\"csrfmiddlewaretoken\" value=\"([^\"]*)\"",curlData)
postdata = 'csrfmiddlewaretoken='+csrfmiddlewaretoken[0]+'&username='+username+'&password='+password
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, "https://instagram.com"+postaction[0])
c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
c.setopt(pycurl.WRITEFUNCTION, buf.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.ENCODING, "")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.REFERER, "https://instagram.com/accounts/login/?next=/oauth/authorize/%3Fclient_id%3D"+clientid[0]+"%26redirect_uri%3Dhttp%3A//web.stagram.com/%26response_type%3Dcode%26scope%3Dlikes%2Bcomments%2Brelationships")
useragent = random.choice(browsers) + str(random.randrange(1,9)) + "." + str(random.randrange(0,50)) + " (" + random.choice(operatingsystems) + "; " + random.choice(operatingsystems) + "; rv:" + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + ")"
c.setopt(pycurl.USERAGENT, useragent)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, postdata)
c.setopt(pycurl.POSTFIELDSIZE, len(postdata))
#c.setopt(pycurl.VERBOSE, True)
c.perform()
curlData = buf.getvalue()
buf.close()
def like():
likecount = 0
sleepcount = 0
for tag in hashtags:
hashtaglikes = 0
nextpage = "http://web.stagram.com/tag/"+tag+"/?vm=list"
#enter hashtag like loop
while nextpage != False and (hashtaglikelimit == 0 or (hashtaglikelimit > 0 and hashtaglikes < hashtaglikelimit)):
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, nextpage)
c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
c.setopt(pycurl.WRITEFUNCTION, buf.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.ENCODING, "")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
useragent = random.choice(browsers) + str(random.randrange(1,9)) + "." + str(random.randrange(0,50)) + " (" + random.choice(operatingsystems) + "; " + random.choice(operatingsystems) + "; rv:" + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + ")"
c.setopt(pycurl.USERAGENT, useragent)
c.perform()
curlData = buf.getvalue()
buf.close()
nextpagelink = re.findall(ur"<a href=\"([^\"]*)\" rel=\"next\">Earlier<\/a>",curlData)
if len(nextpagelink)>0:
nextpage = "http://web.stagram.com"+nextpagelink[0]
else:
nextpage = False
likedata = re.findall(ur"<span class=\"like_button\" id=\"like_button_([^\"]*)\">",curlData)
if len(likedata)>0:
for imageid in likedata:
if hashtaglikelimit > 0 and hashtaglikes >= hashtaglikelimit:
break
repeat = True
while repeat:
randomint = random.randint(1000,9999)
postdata = 'pk='+imageid+'&t='+str(randomint)
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://web.stagram.com/do_like/")
c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
c.setopt(pycurl.WRITEFUNCTION, buf.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.ENCODING, "")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
useragent = random.choice(browsers) + str(random.randrange(1,9)) + "." + str(random.randrange(0,50)) + " (" + random.choice(operatingsystems) + "; " + random.choice(operatingsystems) + "; rv:" + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + "." + str(random.randrange(1,9)) + ")"
c.setopt(pycurl.USERAGENT, useragent)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, postdata)
c.setopt(pycurl.POSTFIELDSIZE, len(postdata))
#c.setopt(pycurl.VERBOSE, True)
c.perform()
postData = buf.getvalue()
buf.close()
if postData == '''{"status":"OK","message":"LIKED"}''':
likecount += 1
hashtaglikes += 1
print "You liked #"+tag+" image "+imageid+"! Like count: "+str(likecount)
repeat = False
sleepcount = 0
if sleeptimer > 0:
time.sleep(sleeptimer)
else:
sleepcount += 1
print "Your account has been rate limited. Sleeping on "+tag+" for "+str(sleepcount)+" minute(s). Liked "+str(likecount)+" photo(s)..."
time.sleep(60)
def main():
login()
like()
if __name__ == "__main__":
main()