Skip to content

Commit 44dd670

Browse files
committed
Update in line with user_followers
Fix issue caused by requiring the user to enter an id manually, changed to automatic user_id = api.username_id. Also made function based and returns list of users following.
1 parent cf0fe1d commit 44dd670

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

examples/user_followings.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,30 @@
77
import time
88
from datetime import datetime
99

10-
user_id = ''
10+
def getTotalFollowing(api, user_id):
11+
"""
12+
Returns the list of people the user is following.
13+
It should be equivalent of calling api.getTotalFollowings from InstagramAPI
14+
"""
1115

12-
API = InstagramAPI("login", "password")
13-
API.login()
16+
api.getUsernameInfo(user_id)
17+
api.LastJson
18+
following = []
19+
next_max_id = True
20+
while next_max_id:
21+
print(next_max_id)
22+
# first iteration hack
23+
if next_max_id is True:
24+
next_max_id = ''
25+
_ = api.getUserFollowings(user_id, maxid=next_max_id)
26+
following.extend(api.LastJson.get('users', []))
27+
next_max_id = api.LastJson.get('next_max_id', '')
28+
return following
1429

15-
API.getUsernameInfo(user_id)
16-
API.LastJson
17-
following = []
18-
next_max_id = True
19-
while next_max_id:
20-
print next_max_id
21-
# first iteration hack
22-
if next_max_id is True:
23-
next_max_id = ''
24-
_ = API.getUserFollowings(user_id, maxid=next_max_id)
25-
following.extend(API.LastJson.get('users', []))
26-
next_max_id = API.LastJson.get('next_max_id', '')
27-
28-
len(following)
29-
unique_following = {
30-
f['pk']: f
31-
for f in following
32-
}
33-
len(unique_following)
30+
if __name__ == "__main__":
31+
api = InstagramAPI("login", "password")
32+
api.login()
33+
user_id = api.username_id
34+
following = getTotalFollowing(api, user_id)
35+
for elem in following:
36+
print(elem['username'])

0 commit comments

Comments
 (0)