Jan-03-2018, 09:40 PM
Hello, I am writing a script using and Instagram API to get data from users. Here is the link for the Github page: https://github.com/LevPasha/Instagram-API-python, and here's the code I have so far. It's trying to get a list of everyone an account follows.
Also, I would like some help understanding what exactly the code starting from line 32 means, as it is not originally mine.
from InstagramAPI import InstagramAPI import time #Setup and login username='example' password='example1' API = InstagramAPI(username,password) API.login() user='alex36540' #this is the user to perform actions on #find User ID def get_userID(user): API.searchUsername(user) try: return API.LastJson["user"]["pk"] except Exception: print("Username doesn't exist") return False #Get Following following=[] def get_Followers(user): next_max_id=True while next_max_id: print(next_max_id) if next_max_id==True:next_max_id='' _=API.getUserFollowings(get_userID(user),maxid=next_max_id) following.extend(API.LastJson.get('users',[])) print(following) next_max_id=API.LastJson.get('next_max_id','') time.sleep(60) len(following) unique_following={ f['pk']:f for f in following } len(unique_following) get_Followers(user)I added the print in line 29 to show the JSON data that was getting added to the list, and this is one list item (there were hundreds of these):
[{'pk': 0000000, 'username': 'example1', 'full_name': 'John Doe', 'is_private': True, 'profile_pic_url': 'https://url.jpg', 'is_verified': False, 'has_anonymous_profile_picture': False, 'reel_auto_archive': 'unset', 'is_favorite': False}]I was wondering how could I change line 28 so that I can pick out specific items I want to get, specifically just pk, username, and full name?
Also, I would like some help understanding what exactly the code starting from line 32 means, as it is not originally mine.