Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.14 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. '''
  4. Cranklin's Instagram Bot v.1.0
  5. ==============================
  6. Check www.cranklin.com for updates
  7. This bot gets you more likes and followers on your Instagram account.
  8. Requirements:
  9. - python > 2.6 but < 3.0
  10. - pycurl library
  11. - web.stagram.com login prior to using the bot
  12. Instructions:
  13. - make sure you have the correct version of Python installed
  14. - make sure you have the pycurl library installed
  15. - log into web.stagram.com with your instagram account and approve the app
  16. - edit between lines 42 and 52
  17. - from the command line, run "python webstagram.py"
  18. - enjoy!
  19. v1.0 updates:
  20. - added browser agent randomizer
  21. - added optional sleep timer
  22. - added optional hashtag limiter
  23. - added a couple extra additions for some people experiencing SSL errors. (thanks Charlie)
  24. *** thank you Nick, John, Max, Shahar, Charlie for the help
  25. '''
  26.  
  27. import os
  28. import pycurl
  29. import cStringIO
  30. import re
  31. import random
  32. import time
  33.  
  34. ##### EDIT THESE BELOW
  35.  
  36. # your instagram username and password
  37. username = "username"
  38. password = "password"
  39.  
  40. #set a sleep timer between each like. Set value to 0 if you don't want it to sleep at all
  41. sleeptimer = 5
  42.  
  43. #set a like limit per hashtag. Set value to 0 if you don't want a limit
  44. hashtaglikelimit = 10000
  45.  
  46. #your list of hashtags
  47. 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"]
  48.  
  49. ##### NO NEED TO EDIT BELOW THIS LINE
  50.  
  51. browsers = ["IE ","Mozilla/","Gecko/","Opera/","Chrome/","Safari/"]
  52. operatingsystems = ["Windows","Linux","OS X","compatible","Macintosh","Intel"]
  53.  
  54. def login():
  55. try:
  56. os.remove("pycookie.txt")
  57. except:
  58. pass
  59.  
  60. buf = cStringIO.StringIO()
  61. c = pycurl.Curl()
  62. c.setopt(pycurl.URL, "http://web.stagram.com")
  63. c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
  64. c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
  65. c.setopt(pycurl.WRITEFUNCTION, buf.write)
  66. c.setopt(pycurl.FOLLOWLOCATION, 1)
  67. c.setopt(pycurl.ENCODING, "")
  68. c.setopt(pycurl.SSL_VERIFYPEER, 0)
  69. c.setopt(pycurl.SSL_VERIFYHOST, 0)
  70. 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)) + ")"
  71. c.setopt(pycurl.USERAGENT, useragent)
  72. c.perform()
  73. curlData = buf.getvalue()
  74. buf.close()
  75.  
  76. 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)
  77. instagramlink = re.findall(ur"href=\"([^\"]*)\">LOG IN",curlData)
  78.  
  79.  
  80.  
  81.  
  82. buf = cStringIO.StringIO()
  83. c = pycurl.Curl()
  84. c.setopt(pycurl.URL, instagramlink[0])
  85. c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
  86. c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
  87. c.setopt(pycurl.WRITEFUNCTION, buf.write)
  88. c.setopt(pycurl.FOLLOWLOCATION, 1)
  89. c.setopt(pycurl.ENCODING, "")
  90. c.setopt(pycurl.SSL_VERIFYPEER, 0)
  91. c.setopt(pycurl.SSL_VERIFYHOST, 0)
  92. 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)) + ")"
  93. c.setopt(pycurl.USERAGENT, useragent)
  94. c.perform()
  95. curlData = buf.getvalue()
  96. buf.close()
  97.  
  98. postaction = re.findall(ur"action=\"([^\"]*)\"",curlData)
  99. csrfmiddlewaretoken = re.findall(ur"name=\"csrfmiddlewaretoken\" value=\"([^\"]*)\"",curlData)
  100.  
  101.  
  102.  
  103.  
  104.  
  105. postdata = 'csrfmiddlewaretoken='+csrfmiddlewaretoken[0]+'&username='+username+'&password='+password
  106.  
  107. buf = cStringIO.StringIO()
  108. c = pycurl.Curl()
  109. c.setopt(pycurl.URL, "https://instagram.com"+postaction[0])
  110. c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
  111. c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
  112. c.setopt(pycurl.WRITEFUNCTION, buf.write)
  113. c.setopt(pycurl.FOLLOWLOCATION, 1)
  114. c.setopt(pycurl.ENCODING, "")
  115. c.setopt(pycurl.SSL_VERIFYPEER, 0)
  116. c.setopt(pycurl.SSL_VERIFYHOST, 0)
  117. 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")
  118. 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)) + ")"
  119. c.setopt(pycurl.USERAGENT, useragent)
  120. c.setopt(pycurl.POST, 1)
  121. c.setopt(pycurl.POSTFIELDS, postdata)
  122. c.setopt(pycurl.POSTFIELDSIZE, len(postdata))
  123. #c.setopt(pycurl.VERBOSE, True)
  124. c.perform()
  125. curlData = buf.getvalue()
  126. buf.close()
  127.  
  128.  
  129.  
  130. def like():
  131. likecount = 0
  132. sleepcount = 0
  133. for tag in hashtags:
  134. hashtaglikes = 0
  135. nextpage = "http://web.stagram.com/tag/"+tag+"/?vm=list"
  136. #enter hashtag like loop
  137. while nextpage != False and (hashtaglikelimit == 0 or (hashtaglikelimit > 0 and hashtaglikes < hashtaglikelimit)):
  138. buf = cStringIO.StringIO()
  139. c = pycurl.Curl()
  140. c.setopt(pycurl.URL, nextpage)
  141. c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
  142. c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
  143. c.setopt(pycurl.WRITEFUNCTION, buf.write)
  144. c.setopt(pycurl.FOLLOWLOCATION, 1)
  145. c.setopt(pycurl.ENCODING, "")
  146. c.setopt(pycurl.SSL_VERIFYPEER, 0)
  147. c.setopt(pycurl.SSL_VERIFYHOST, 0)
  148. 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)) + ")"
  149. c.setopt(pycurl.USERAGENT, useragent)
  150. c.perform()
  151. curlData = buf.getvalue()
  152. buf.close()
  153.  
  154. nextpagelink = re.findall(ur"<a href=\"([^\"]*)\" rel=\"next\">Earlier<\/a>",curlData)
  155. if len(nextpagelink)>0:
  156. nextpage = "http://web.stagram.com"+nextpagelink[0]
  157. else:
  158. nextpage = False
  159.  
  160. likedata = re.findall(ur"<span class=\"like_button\" id=\"like_button_([^\"]*)\">",curlData)
  161. if len(likedata)>0:
  162. for imageid in likedata:
  163. if hashtaglikelimit > 0 and hashtaglikes >= hashtaglikelimit:
  164. break
  165. repeat = True
  166. while repeat:
  167. randomint = random.randint(1000,9999)
  168.  
  169. postdata = 'pk='+imageid+'&t='+str(randomint)
  170. buf = cStringIO.StringIO()
  171. c = pycurl.Curl()
  172. c.setopt(pycurl.URL, "http://web.stagram.com/do_like/")
  173. c.setopt(pycurl.COOKIEFILE, "pycookie.txt")
  174. c.setopt(pycurl.COOKIEJAR, "pycookie.txt")
  175. c.setopt(pycurl.WRITEFUNCTION, buf.write)
  176. c.setopt(pycurl.FOLLOWLOCATION, 1)
  177. c.setopt(pycurl.ENCODING, "")
  178. c.setopt(pycurl.SSL_VERIFYPEER, 0)
  179. c.setopt(pycurl.SSL_VERIFYHOST, 0)
  180. 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)) + ")"
  181. c.setopt(pycurl.USERAGENT, useragent)
  182. c.setopt(pycurl.POST, 1)
  183. c.setopt(pycurl.POSTFIELDS, postdata)
  184. c.setopt(pycurl.POSTFIELDSIZE, len(postdata))
  185. #c.setopt(pycurl.VERBOSE, True)
  186. c.perform()
  187. postData = buf.getvalue()
  188. buf.close()
  189. if postData == '''{"status":"OK","message":"LIKED"}''':
  190. likecount += 1
  191. hashtaglikes += 1
  192. print "You liked #"+tag+" image "+imageid+"! Like count: "+str(likecount)
  193. repeat = False
  194. sleepcount = 0
  195. if sleeptimer > 0:
  196. time.sleep(sleeptimer)
  197. else:
  198. sleepcount += 1
  199. print "Your account has been rate limited. Sleeping on "+tag+" for "+str(sleepcount)+" minute(s). Liked "+str(likecount)+" photo(s)..."
  200. time.sleep(60)
  201.  
  202. def main():
  203. login()
  204. like()
  205.  
  206. if __name__ == "__main__":
  207. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement