1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-11-04 09:22:29 +01:00

Implementation of get_id_by_username()

+ updated README.md
This commit is contained in:
André Koch-Kramer 2016-08-02 21:27:39 +02:00
parent e6ca038e25
commit 77d0d272fc
2 changed files with 16 additions and 3 deletions

View File

@ -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 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). [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 ...] ./instaloader.py profile [profile ...]
``` ```
@ -67,8 +68,14 @@ for f in followees:
pass pass
``` ```
`get_followees()` also returns unique IDs for all loaded followees. These IDs stay unchanged even Each Instagram profile has its own unique ID which stays unmodified even if a user changes his/her
if a user changes his/her username. To get the current username of a profile, given this unique ID 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: `get_username_by_id()` can be used. For example:
```python ```python
instaloader.get_username_by_id(session, followees[0]['id']) instaloader.get_username_by_id(session, followees[0]['id'])

View File

@ -80,6 +80,12 @@ def get_username_by_id(session, profile_id):
raise LoginRequiredException("Login required to determine username (id: " + raise LoginRequiredException("Login required to determine username (id: " +
str(profile_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): def epoch_to_string(epoch):
return datetime.datetime.fromtimestamp(epoch).strftime('%Y-%m-%d_%H-%M-%S') return datetime.datetime.fromtimestamp(epoch).strftime('%Y-%m-%d_%H-%M-%S')