Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.14 KB | None | 0 0
  1.  
  2. """
  3. instabot example
  4.  
  5. Collects the information about your account
  6. every hour in username.tsv file.
  7. """
  8.  
  9. import os
  10. import random
  11. import sys
  12. import time
  13. import argparse
  14. import instabot
  15. import instaMaker
  16. import multiprocessing
  17.  
  18.  
  19. # USERNAME = "tester9209"
  20. # PASS = "nousername0"
  21. # USERNAME = "moneer7358"
  22. # PASS = "NubhR1991!"
  23. # USERNAME = "bagdidi1876"
  24. # PASS = "nousername0"
  25. # USERNAME = "bagdidi18321"
  26. # PASS = "nousername0"
  27. # USERNAME = "ahmadon7641"
  28. # PASS = "nousername0"
  29. USERNAME = ""
  30. PASS = ""
  31.  
  32.  
  33.  
  34.  
  35. def likeMediasByUsers():
  36. """
  37. instabot example
  38. Workflow:
  39. Like last medias by users.
  40. """
  41.  
  42. import argparse
  43. import sys
  44.  
  45. import os
  46.  
  47. sys.path.append(os.path.join(sys.path[0], '../'))
  48. from instabot import Bot
  49.  
  50. parser = argparse.ArgumentParser(add_help=True)
  51. parser.add_argument('-u', type=str, help="username")
  52. parser.add_argument('-p', type=str, help="password")
  53. parser.add_argument('-proxy', type=str, help="proxy")
  54. parser.add_argument('users', type=str, nargs='+', help='users')
  55. args = parser.parse_args()
  56.  
  57. bot = Bot()
  58. bot.login(username=USERNAME, password=PASS,
  59. proxy=args.proxy)
  60.  
  61. for username in args.users:
  62. bot.like_user(username, filtration=False)
  63.  
  64.  
  65.  
  66.  
  67. def like_users():
  68. sys.path.append(os.path.join(sys.path[0], '../../'))
  69. from instabot import Bot
  70.  
  71. bot = Bot()
  72. bot.login()
  73.  
  74. # print("Current script's schedule:")
  75. # follow_followers_list = bot.read_list_from_file("follow_followers.txt")
  76. # print("Going to follow followers of:", follow_followers_list)
  77. follow_following_list = bot.read_list_from_file("follow_following.txt")
  78. print("Going to follow following of:", follow_following_list)
  79. # like_hashtags_list = bot.read_list_from_file("like_hashtags.txt")
  80. # print("Going to like hashtags:", like_hashtags_list)
  81. # like_users_list = bot.read_list_from_file("like_users.txt")
  82. # print("Going to like users:", like_users_list)
  83.  
  84. tasks_list = []
  85. # for item in follow_followers_list:
  86. # tasks_list.append((bot.follow_followers, {'user_id': item, 'nfollows': None}))
  87. for item in follow_following_list:
  88. tasks_list.append((bot.follow_following, {'user_id': item}))
  89. # for item in like_hashtags_list:
  90. # tasks_list.append((bot.like_hashtag, {'hashtag': item, 'amount': None}))
  91. # for item in like_users_list:
  92. # tasks_list.append((bot.like_user, {'user_id': item, 'amount': None}))
  93.  
  94. # shuffle(tasks_list)
  95. for func, arg in tasks_list:
  96. func(**arg)
  97.  
  98.  
  99.  
  100.  
  101. def comment_on_hashTags():
  102. """
  103. instabot example
  104.  
  105. Dependencies:
  106. You must have a file with comments to post.
  107. The file should have one comment per line.
  108.  
  109. Notes:
  110. You can change file and add there your comments.
  111. """
  112.  
  113.  
  114.  
  115. sys.path.append(os.path.join(sys.path[0], '../../'))
  116. from instabot import Bot
  117.  
  118. # if len(sys.argv) < 3:
  119. # print ("USAGE: Pass a path to the file with comments and an hastag to comment")
  120. # print ("Example: %s comments_emoji.txt dog cat" % sys.argv[0])
  121. # exit()
  122.  
  123. comments_file_name = "comments.txt"
  124. hashtags = "dog"
  125. if not os.path.exists(comments_file_name):
  126. print ("Can't find '%s' file." % comments_file_name)
  127. exit()
  128.  
  129. bot = Bot(comments_file=comments_file_name)
  130. bot.login()
  131. for hashtag in hashtags:
  132. bot.comment_hashtag(hashtag)
  133. bot.logout()
  134.  
  135.  
  136. def like_from_feed():
  137. """
  138. instabot example
  139. Workflow:
  140. Like rescent medias from your timeline feed.
  141. """
  142.  
  143. sys.path.append(os.path.join(sys.path[0], '../'))
  144. from instabot import Bot
  145.  
  146. parser = argparse.ArgumentParser(add_help=True)
  147. parser.add_argument('-u', type=str, help="username")
  148. parser.add_argument('-p', type=str, help="password")
  149. parser.add_argument('-proxy', type=str, help="proxy")
  150. args = parser.parse_args()
  151.  
  152. bot = Bot()
  153. bot.login(username=args.u, password=args.p,
  154. proxy=args.proxy)
  155.  
  156. wait = 5 * 60 # in seconds
  157.  
  158. while True:
  159. bot.like_timeline()
  160. time.sleep(wait)
  161.  
  162.  
  163.  
  164.  
  165. def repost_users_posts():
  166. """
  167. instabot example
  168.  
  169. Workflow:
  170. Repost best photos from users to your account
  171. By default bot checks username_database.txt
  172. The file should contain one username per line!
  173. """
  174.  
  175. from tqdm import tqdm
  176.  
  177. sys.path.append(os.path.join(sys.path[0], '../'))
  178. from instabot import Bot
  179. from instabot.bot.bot_support import read_list_from_file
  180.  
  181. USERNAME_DATABASE = 'followed.txt'
  182. POSTED_MEDIAS = 'posted_medias.txt'
  183.  
  184. def repost_best_photos(my_bot, users, amount=1):
  185. medias = get_not_used_medias_from_users(my_bot, users)
  186. medias = sort_best_medias(my_bot, medias, amount)
  187. for media in tqdm(medias, desc='Reposting photos'):
  188. repost_photo(my_bot, media)
  189.  
  190. def sort_best_medias(my_bot, media_ids, amount=1):
  191. best_medias = [my_bot.get_media_info(media)[0] for media in tqdm(media_ids, desc='Getting media info')]
  192. best_medias = sorted(best_medias, key=lambda x: (x['like_count'], x['comment_count']), reverse=True)
  193. return [best_media['pk'] for best_media in best_medias[:amount]]
  194.  
  195. def get_not_used_medias_from_users(my_bot, users=None, users_path=USERNAME_DATABASE):
  196. if not users:
  197. users = read_list_from_file(users_path)
  198. users = map(str, users)
  199. total_medias = []
  200. for user in users:
  201. medias = my_bot.get_user_medias(user, filtration=False)
  202. medias = [media for media in medias if not exists_in_posted_medias(media)]
  203. total_medias.extend(medias)
  204. return total_medias
  205.  
  206. def exists_in_posted_medias(new_media_id, path=POSTED_MEDIAS):
  207. medias = read_list_from_file(path)
  208. return str(new_media_id) in medias
  209.  
  210. def update_posted_medias(new_media_id, path=POSTED_MEDIAS):
  211. medias = read_list_from_file(path)
  212. medias.append(str(new_media_id))
  213. with open(path, 'w') as file:
  214. file.writelines('\n'.join(medias))
  215. return True
  216.  
  217. def repost_photo(my_bot, new_media_id, path=POSTED_MEDIAS):
  218. if exists_in_posted_medias(new_media_id, path):
  219. my_bot.logger.warning("Media {0} was uploaded earlier".format(new_media_id))
  220. return False
  221. photo_path = my_bot.download_photo(new_media_id, description=True)
  222. if not photo_path:
  223. return False
  224. with open(photo_path[:-3] + 'txt', 'r') as f:
  225. text = ''.join(f.readlines())
  226. if my_bot.upload_photo(photo_path, text):
  227. update_posted_medias(new_media_id, path)
  228. my_bot.logger.info('Media_id {0} is saved in {1}'.format(new_media_id, path))
  229.  
  230. parser = argparse.ArgumentParser(add_help=True)
  231. parser.add_argument('-u', type=str, help="username")
  232. parser.add_argument('-p', type=str, help="password")
  233. parser.add_argument('-proxy', type=str, help="proxy")
  234. parser.add_argument('-file', type=str, help="users filename")
  235. parser.add_argument('-amount', type=int, help="amount", default=1)
  236. parser.add_argument('users', type=str, nargs='*', help='users')
  237. args = parser.parse_args()
  238.  
  239. bot = Bot()
  240. bot.login()
  241.  
  242. users = None
  243. if args.users:
  244. users = args.users
  245. elif args.file:
  246. users = read_list_from_file(args.file)
  247.  
  248. repost_best_photos(bot, users, args.amount)
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. def get_ushers_medias_list():
  257. bot = instabot.Bot()
  258. bot.login(username=USERNAME, password=PASS)
  259.  
  260. medias_list = bot.get_user_medias("mohamdfakhri")
  261.  
  262. bot.comments_file = "comments.txt"
  263. bot.comment_delay = 3
  264. # bot.comment_medias(medias_list)
  265.  
  266. for item in medias_list:
  267. bot.comment(item, "@ludwigvonriviera")
  268. time.sleep(3)
  269. print "done"
  270.  
  271.  
  272.  
  273. def initializeBot():
  274. bot = instabot.Bot()
  275. bot.login(username=USERNAME, password=PASS)
  276. bot.comment_delay = 3
  277. return bot
  278.  
  279.  
  280. def get_user_media(bot, victim):
  281. medias = bot.get_total_user_medias(victim)
  282. # medias = bot.get_user_medias(victim)
  283. print "Found " + str(len(medias)) + " Medias."
  284. return medias
  285.  
  286. def comment_all_medias(bot, medias, victim_to_tag):
  287. for idx, media in enumerate(medias):
  288. print "Comment " + str(idx) + "."
  289. bot.comment(media, "@" + victim_to_tag)
  290. print "Comment " + str(idx) + " Done."
  291.  
  292. time.sleep(random.randrange(5, 10))
  293.  
  294.  
  295.  
  296. def upload_photo_and_tag_victim(bot, victim, photo):
  297. bot.upload_photo(photo, "@" + victim)
  298. print "Upladed Photo."
  299.  
  300.  
  301.  
  302.  
  303. if __name__ == '__main__':
  304. text_file = open("comments.txt", "r")
  305. comments = text_file.readlines()
  306. text_file.close()
  307.  
  308. text_file = open("images.txt", "r")
  309. images = text_file.readlines()
  310. text_file.close()
  311.  
  312.  
  313.  
  314.  
  315. print "Do you have an Instagram account? \n 1. Yes\n No"
  316. choice = input()
  317.  
  318. if choice == 1:
  319. print "Enter Username: "
  320. USERNAME = raw_input()
  321. print "Enter Password: "
  322. PASS = raw_input()
  323.  
  324.  
  325. if choice == 2:
  326. USERNAME, PASS = instaMaker.main()
  327.  
  328. bot = initializeBot()
  329.  
  330.  
  331. print "What would you want to do?"
  332. print "1. Comment a Victim (a) on images of another Victim (b)"
  333. print "2. Comment sentences on a Victims images"
  334. print "3. Upload images and tag Victim"
  335.  
  336.  
  337. choice = input()
  338.  
  339.  
  340. if choice == 1:
  341. print "Enter Victim (a) - The one to be tagged:"
  342. victim_a = raw_input()
  343. print "Enter Victim (b) - The one with the images:"
  344. victim_b = raw_input()
  345.  
  346. print "Getting medias"
  347. medias = get_user_media(bot, victim_b)
  348. print "Commenting"
  349. comment_all_medias(bot, medias, victim_a)
  350.  
  351. quit()
  352.  
  353.  
  354. if choice == 2:
  355. print "Enter Victim:"
  356. victim = raw_input()
  357.  
  358. # Get media list
  359. medias = get_user_media(bot, victim)
  360.  
  361. # Iterate media and comment
  362. bot.comment_delay = 0
  363. for media in medias:
  364. bot.comment(media, random.choice(comments))
  365. time.sleep(random.randrange(5, 10))
  366.  
  367. quit()
  368.  
  369.  
  370. if choice == 3:
  371. print "Enter Victim:"
  372. victim = raw_input()
  373.  
  374. print "Enter Number of photos: 1-" + str(len(images)) + " MAX!"
  375. num_of_uploads = input()
  376.  
  377. # Upload image
  378. for idx, curr_pic in enumerate(images):
  379. if idx > num_of_uploads:
  380. break
  381. print "Uploading " + str(idx + 1) + " of " + str(num_of_uploads)
  382. upload_photo_and_tag_victim(bot, victim, (random.choice(images)).strip())
  383. print "Uploaded " + str(idx + 1) + " of " + str(num_of_uploads)
  384. time.sleep(random.randrange(10, 20))
  385.  
  386. quit()
  387.  
  388.  
  389. source_media_profile = "mdadaaa"
  390.  
  391.  
  392. # upload_photo_and_tag_victim(bot, "@tester9209", "Image002.jpg")
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403. # get_users_medias_list()
  404. # repost_users_posts()
  405. # like_from_feed()
  406. # comment_on_hashTags()
  407. # like_users()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement