Skip to content

Commit

Permalink
Update get_user_basic_details and get_user_friends methods & docs.
Browse files Browse the repository at this point in the history
Add new datapoints to get_user_basic_details and now prints formatted data. Fix get_user_friends for verified users. Update documentation for get_user_basic_details.
  • Loading branch information
iSarabjitDhiman committed May 20, 2023
1 parent 6cf4aee commit a99691e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
10 changes: 7 additions & 3 deletions instagpy/docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,17 @@ get_user_info(username)
## Get a brief overview of a user.

```python
get_user_basic_details(username)
get_user_basic_details(username,print_formatted=False)

"""
Check if user is logged in.
Get a brief overview of an Instagram Profile.
Args:
username (str, optional): Instagram Username. Defaults to None.
print_formatted (bool, optional): Print Data in a Structure way. Defaults to False.
Returns:
bool: Returns True if user is logged in.
dict: User Data.
"""
```

Expand Down
23 changes: 20 additions & 3 deletions instagpy/instagpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,33 @@ def get_user_data(self, user_id):
self.shuffle_session()
return response

def get_user_basic_details(self, username=None):
def get_user_basic_details(self, username=None, print_formatted=False):
"""Get a brief overview of an Instagram Profile.
Args:
username (str, optional): Instagram Username. Defaults to None.
print_formatted (bool, optional): Print Data in a Structure way. Defaults to False.
Returns:
dict: User Data.
"""
if username is None:
raise Exception("Username can't be blank. Set a username.")
user = {}
user_info = self.get_user_info(username)['data']['user']
user['id'] = user_info['id']
user['username'] = user_info['username']
user['full_name'] = user_info['full_name']
user['bio'] = user_info['biography']
user['is_private'] = user_info['is_private']
user['is_verified'] = user_info['is_verified']
user['username'] = user_info['username']
user['follower_count'] = user_info['edge_followed_by']['count']
user['following_count'] = user_info['edge_follow']['count']
user['media_count'] = user_info['edge_owner_to_timeline_media']['count']
user['website'] = user_info['external_url']
if print_formatted:
for key, value in user.items():
print(f"{key} : {value}")
return user

def get_user_friends(self, username, followers_list=False, followings_list=False, end_cursor=None, max=None):
Expand Down Expand Up @@ -265,9 +281,10 @@ def get_user_friends(self, username, followers_list=False, followings_list=False
response = make_request(
url, params=query_params, session=self.session, max_retries=self.max_retries)
if followers_list and user['is_verified']:
data = data['data']['user']['edge_followed_by']
data = response['data']['user']['edge_followed_by']
has_next_page = data['page_info']['has_next_page']
end_cursor = data['page_info']['end_cursor']
data = data['edges']
else:
data = response['users']
if 'next_max_id' in response.keys():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "0.1.0"
VERSION = "0.1.1"
SHORT_DESCRIPTION = "InstaGPy is an Instagram Unofficial API to extract data from Instargam Profiles. Scrape data from user's profile like username, userid, bio, email, phone, followers/followings list, profile media, account_type, etc."

with open("requirements.txt") as file:
Expand Down

0 comments on commit a99691e

Please sign in to comment.