Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. from InstagramAPI import InstagramAPI
  2. import time
  3. from datetime import datetime
  4.  
  5. time_start = time.time()
  6.  
  7. login = ""
  8. password = ""
  9. user_id = '5612607660'
  10.  
  11. # stop conditions, the script will end when first of them will be true
  12. count = 1000
  13.  
  14. API = InstagramAPI(login, password)
  15. API.login()
  16.  
  17. user_feed_list = API.getTotalUserFeed(user_id)
  18. # print(user_feed_list[0])
  19.  
  20. for i in user_feed_list:
  21.     has_more_comments = True
  22.     max_id = ''
  23.     comments = []
  24.  
  25.     id_media = i['id']
  26.  
  27.     while has_more_comments:
  28.         _ = API.getMediaComments(id_media, max_id=max_id)
  29.         # comments' page come from older to newer, lets preserve desc order in full list
  30.         for c in reversed(API.LastJson['comments']):
  31.             comments.append(c)
  32.         has_more_comments = API.LastJson.get('has_more_comments', False)
  33.         # evaluate stop conditions
  34.         if count and len(comments) >= count:
  35.             comments = comments[:count]
  36.             # stop loop
  37.             has_more_comments = False
  38.             print("stopped by count")
  39.         # next page
  40.         if has_more_comments:
  41.             max_id = API.LastJson.get('next_max_id', '')
  42.             time.sleep(2)
  43.  
  44.     print(comments)
  45.  
  46.     has_more_comments = True
  47.     max_id = ''
  48.     comments = []
  49.  
  50. time_end = time.time()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement