From 77d0d272fc029250ee27bd8ec1da5e79a451aeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Koch-Kramer?= Date: Tue, 2 Aug 2016 21:27:39 +0200 Subject: [PATCH] Implementation of get_id_by_username() + updated README.md --- README.md | 13 ++++++++++--- instaloader.py | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f11aaa..4f1c9b7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ Ensure having [Python](https://www.python.org/) (at least version 3.3) and If you intend to use this tool under Windows, it is highly recommended to first install [win-unicode-console](https://github.com/Drekin/win-unicode-console). -After having [downloaded instaloader.py](https://github.com/Thammus/instaloader/releases), you invoke it with +After having [downloaded instaloader.py](https://github.com/Thammus/instaloader/releases), you +invoke it with ``` ./instaloader.py profile [profile ...] ``` @@ -67,8 +68,14 @@ for f in followees: pass ``` -`get_followees()` also returns unique IDs for all loaded followees. These IDs stay unchanged even -if a user changes his/her username. To get the current username of a profile, given this unique ID +Each Instagram profile has its own unique ID which stays unmodified even if a user changes his/her +username. To get said ID, given the profile's name, you may call +```python +instaloader.get_id_by_username(PROFILE_NAME) +``` + +`get_followees()` also returns unique IDs for all loaded followees. To get the current username of a +profile, given this unique ID `get_username_by_id()` can be used. For example: ```python instaloader.get_username_by_id(session, followees[0]['id']) diff --git a/instaloader.py b/instaloader.py index 7cb4120..c88bf6e 100755 --- a/instaloader.py +++ b/instaloader.py @@ -80,6 +80,12 @@ def get_username_by_id(session, profile_id): raise LoginRequiredException("Login required to determine username (id: " + str(profile_id) + ").") +def get_id_by_username(profile): + data = get_json(profile, get_anonymous_session()) + if len(data["entry_data"]) == 0 or "ProfilePage" not in data("entry_data"): + raise ProfileNotExistsException("Profile {0} does not exist.".format(profile)) + return int(data['entry_data']['ProfilePage'][0]['user']['id']) + def epoch_to_string(epoch): return datetime.datetime.fromtimestamp(epoch).strftime('%Y-%m-%d_%H-%M-%S')