Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.19 KB | None | 0 0
  1. # DO NOT TOUCH THESE THREE CONST VARIABLES
  2. POPULAR = 1
  3. LIKE = 2
  4. LIKE_FOLLOW = 3
  5. UNFOLLOW = 4
  6.  
  7. #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
  8. TAGS = ["startups", "success", "health", "money", "nutrition", "gym", "entrepreneur", "college"]
  9.  
  10. #IF YOU WANT THE ACTION TO FOLLOW OR LIKE SOMEONE BASED ON THE CHOSEN TAG CHANGE IT TO EITHER
  11. # ACTION=POPULAR - Popular follows people who have liked an image on the popular page (this means they are active users)
  12. # ACTION=LIKE
  13. # ACTION=LIKE_FOLLOW
  14. ACTION = LIKE_FOLLOW
  15.  
  16. #CHANGE THE NUMBER OF LIKES OR FOLLOWS YOU WANT TO OCCUR, e.g. NO MORE THEN 100 is the current setting
  17. MAX_COUNT = 1000
  18.  
  19. #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)
  20. MAX_SECS = 1
  21.  
  22. #Hit the URL below, the returned GET request will give you an auth token from Instagram.
  23. #
  24. #THE AUTH TOKEN IS THE KEY THAT YOU GET WHEN YOU SIGN IN WITH THE FOLLOWING CLIENT URL.
  25. #DOES NOT NEED TO CHANGE UNLESS AUTH TOKEN EXPIRES
  26. #
  27. #
  28. # https://api.instagram.com/oauth/authorize/?client_id=1627c123e3fc481791e0d6be16ff57a0&redirect_uri=http://yoururl.com&response_type=token&display=touch&scope=likes+relationships
  29. #
  30. auth_token = "54537579.073f3c2.bbf5935671a4447ea1844ea4d76b7b6b"
  31. client_id = '073f3c26528c451d85f8fdbba5956b73'
  32.  
  33. ######DO NOT TOUCH ANYTHING UNDER HERE UNLESS YOU KNOW WHAT YOU ARE DOING, DANGER DANGER, SERIOUS PROBLEMS IF YOU TOUCH ###########
  34.  
  35. print "FOLLOW PIE BEGINS - GRAB A SLICE AND SIT BACK"
  36. print ""
  37. print "The script will now proceed"
  38. print ""
  39. print ""
  40.  
  41. import time, random
  42. import urllib,json,urllib2
  43.  
  44. 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'
  45. headers = { 'User-Agent' : user_agent,
  46. "Content-type": "application/x-www-form-urlencoded"
  47. }
  48. likedDict = {}
  49.  
  50.  
  51. def likePicture(pictureId):
  52. liked = 0
  53. try:
  54. urlLike = "https://api.instagram.com/v1/media/%s/likes"
  55. values = {'access_token' : auth_token,
  56. 'client_id' : client_id}
  57. newLike = urlLike % (pictureId)
  58. print newLike
  59. data = urllib.urlencode(values)
  60. req = urllib2.Request(newLike,data,headers)
  61. response = urllib2.urlopen(req)
  62. result = response.read()
  63. dataObj = json.loads(result)
  64. liked = 1
  65. except Exception, e:
  66. print e
  67. return liked
  68.  
  69. FOLLOWS = 1
  70. DOES_NOT_FOLLOW = 0
  71. PENDING = 2
  72.  
  73.  
  74. #unfollow users who don't follow you.
  75. def unfollow_users(next_url=None, num_unfollows=0):
  76. if next_url == None:
  77. urlUserMedia = "https://api.instagram.com/v1/users/self/follows?access_token=%s" % (auth_token)
  78. else:
  79. urlUserMedia = next_url
  80.  
  81. values = {
  82. 'client_id' : client_id}
  83. try:
  84. data = urllib.urlencode(values)
  85. req = urllib2.Request(urlUserMedia,None,headers)
  86. response = urllib2.urlopen(req)
  87. result = response.read()
  88. dataObj = json.loads(result)
  89. next_url = None
  90. if dataObj.get('pagination') is not None:
  91. next_url = dataObj.get('pagination')["next_url"]
  92.  
  93. for user in dataObj['data']:
  94. for k, v in user.iteritems():
  95. if k == "id":
  96. userId = v
  97. relationship = get_relationship(userId)
  98. if relationship == DOES_NOT_FOLLOW:
  99. result = unfollow_user(userId)
  100. num_unfollows = num_unfollows+result
  101. seconds=random.randint(1, MAX_SECS)
  102. time.sleep(seconds)
  103. print num_unfollows
  104. if num_unfollows % 10 == 0:
  105. print "Unfollowed %s users " % num_unfollows
  106.  
  107. if next_url is not None:
  108. unfollow_users(next_url, num_unfollows)
  109.  
  110. except Exception, e:
  111. print e
  112. return num_unfollows
  113.  
  114.  
  115. def get_relationship(userId):
  116. unfollowed=0
  117.  
  118. followUrl = "https://api.instagram.com/v1/users/%s/relationship?access_token=%s&client_id=%s" % (userId, auth_token, client_id)
  119.  
  120. values = {'access_token' : auth_token,
  121. 'client_id' : client_id}
  122. try:
  123. data = urllib.urlencode(values)
  124. req = urllib2.Request(followUrl,None,headers)
  125. response = urllib2.urlopen(req)
  126. result = response.read()
  127. dataObj = json.loads(result)
  128. status = dataObj["data"]
  129. incoming = status["incoming_status"]
  130. print '%s - %s ' % (userId, incoming)
  131. if incoming != "followed_by":
  132. return DOES_NOT_FOLLOW
  133. else:
  134. return FOLLOWS
  135. except Exception, e:
  136. print e
  137. return unfollowed
  138.  
  139.  
  140. def unfollow_user(userId):
  141. unfollowed=0
  142. followUrl = "https://api.instagram.com/v1/users/%s/relationship?action=allow"
  143.  
  144. values = {'access_token' : auth_token,
  145. 'action' : 'unfollow',
  146. 'client_id' : client_id}
  147. try:
  148. newFollow = followUrl % (userId)
  149. data = urllib.urlencode(values)
  150. req = urllib2.Request(newFollow,data,headers)
  151. response = urllib2.urlopen(req)
  152. result = response.read()
  153. dataObj = json.loads(result)
  154. unfollowed = 1
  155. except Exception, e:
  156. print e
  157. return unfollowed
  158.  
  159.  
  160. def followUser(userId):
  161. followed=0
  162. followUrl = "https://api.instagram.com/v1/users/%s/relationship?action=allow"
  163.  
  164. values = {'access_token' : auth_token,
  165. 'action' : 'follow',
  166. 'client_id' : client_id}
  167. try:
  168. newFollow = followUrl % (userId)
  169. print newFollow
  170. data = urllib.urlencode(values)
  171. req = urllib2.Request(newFollow,data,headers)
  172. response = urllib2.urlopen(req)
  173. result = response.read()
  174. print result
  175. dataObj = json.loads(result);
  176. followed = 1
  177.  
  178. except Exception, e:
  179. print e
  180.  
  181. return followed
  182.  
  183.  
  184. def likeAndFollowUser(userId):
  185. numLikesFollows=0
  186. urlUserMedia = "https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s" % (userId,auth_token)
  187. values = {
  188. 'client_id' : client_id}
  189. try:
  190. print urlUserMedia
  191. data = urllib.urlencode(values)
  192. req = urllib2.Request(urlUserMedia,None,headers)
  193. response = urllib2.urlopen(req)
  194. result = response.read()
  195. dataObj = json.loads(result);
  196. picsToLike = random.randint(1, 3)
  197. print "Liking %s pics for user %s" % (picsToLike, userId)
  198. countPicViews=0
  199. for picture in dataObj['data']:
  200. print "Liking picture %s " % picture['id']
  201. likePicture(picture['id'])
  202. countPicViews = countPicViews+1
  203. numLikesFollows = numLikesFollows+1
  204. if(countPicViews == picsToLike):
  205. break
  206. followed=1
  207. except Exception, e:
  208. print e
  209.  
  210. followUser(userId)
  211. return numLikesFollows
  212.  
  213. if(ACTION == LIKE or ACTION == LIKE_FOLLOW):
  214. def likeUsers(max_results,max_id,tag,c,fllw):
  215. urlFindLike="https://api.instagram.com/v1/tags/%s/media/recent?client_id=1627c123e3fc481791e0d6be16ff57a0&access_token=%s" % (tag,auth_token);
  216.  
  217. urlLike="https://api.instagram.com/v1/media/%s/likes"
  218. values = {'access_token' : auth_token,
  219. 'client_id' : client_id,
  220. 'max_id' : max_id}
  221.  
  222. f = urllib.urlopen(urlFindLike)
  223. dataObj = json.loads(f.read())
  224. f.close()
  225. numResults = len(dataObj['data'])
  226. pictureId=0
  227. for likeObj in dataObj['data']:
  228. print ''
  229. pictureId = likeObj['id']
  230. paginationId = dataObj["pagination"]['next_max_id']
  231. user = likeObj['user']
  232. userId = user['id']
  233. try:
  234. numLikes = likedDict[pictureId]
  235. numLikes = numLikes+1
  236. likedDict[pictureId] = numLikes
  237. except:
  238. numLikes = 1
  239. likedDict[pictureId] = numLikes
  240.  
  241. try:
  242. result = likePicture(pictureId)
  243. if(ACTION==LIKE_FOLLOW):
  244. print "Following user %s" % userId
  245. fresult=followUser(userId)
  246. fllw=fllw+fresult
  247. c=c+result
  248. seconds=random.randint(1, MAX_SECS)
  249. time.sleep(seconds)
  250. if(c%10==0):
  251. print "Liked %s: %s" % (tag,c)
  252. if(fllw%10==0 and fllw!=0):
  253. print "Followed %s: %s" % (tag,fllw)
  254. if(c==max_results):
  255. break
  256. except Exception, e:
  257. print e
  258. if(c!=max_results):
  259. likeUsers(max_results,paginationId,tag,c,fllw)
  260. return c,fllw
  261. print ''
  262.  
  263. for tag in TAGS:
  264. c=0
  265. f=0
  266. c,f=likeUsers(MAX_COUNT,0,tag,c,f)
  267. print "Liked %s: Followed %s: for tag %s" %(c,f,tag)
  268.  
  269. for likes in likedDict:
  270. print "%s = %s" % (likes, likedDict[likes])
  271. elif(ACTION==POPULAR):
  272. urlPopular="https://api.instagram.com/v1/media/popular?client_id=1627c123e3fc481791e0d6be16ff57a0";
  273. f = urllib.urlopen(urlPopular)
  274. dataObj=json.loads(f.read())
  275. f.close()
  276. i=0
  277. c=0
  278. l=0
  279. for obj in dataObj['data']:
  280. for comment in obj['likes']['data']:
  281. myid=comment['id']
  282. try:
  283. result=likeAndFollowUser(myid)
  284. if(result>0):
  285. c=c+1
  286. l=l+result
  287. if(c%10==0):
  288. print "Followed %s" % c
  289. seconds=random.randint(1, MAX_SECS)
  290. time.sleep(seconds)
  291. except Exception, e:
  292. print e
  293. if(c==MAX_COUNT):
  294. break
  295. if(c==MAX_COUNT):
  296. break
  297.  
  298.  
  299. ""
  300. print ""
  301. print "Followed %s" % (c);
  302. print "Liked %s" % (l);
  303. elif(ACTION==UNFOLLOW):
  304. num_unfollows = unfollow_users()
  305. print "Number of users unfollowed is %s " % num_unfollows
  306.  
  307. print "FOLLOW PIE ENDS - HAPPY DIGESTING"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement