1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-09-11 16:22:24 +02:00

Print profile suggestions when profile not found

Relates to #496.
This commit is contained in:
André Koch-Kramer 2020-01-27 11:14:04 +01:00
parent 8764947d10
commit 302145f54f
2 changed files with 13 additions and 1 deletions

View File

@ -926,8 +926,11 @@ class Instaloader:
:return: Instance of current profile
"""
profile = None
with suppress(ProfileNotExistsException):
profile_name_not_exists_err = None
try:
profile = Profile.from_username(self.context, profile_name)
except ProfileNotExistsException as err:
profile_name_not_exists_err = err
id_filename = self._get_id_filename(profile_name)
try:
with open(id_filename, 'rb') as id_file:
@ -960,6 +963,8 @@ class Instaloader:
if profile is not None:
self.save_profile_id(profile)
return profile
if profile_name_not_exists_err:
raise profile_name_not_exists_err
raise ProfileNotExistsException("Profile {0} does not exist.".format(profile_name))
def download_profiles(self, profiles: Set[Profile],

View File

@ -534,6 +534,13 @@ class Profile:
self._has_full_metadata = True
self._rhx_gis = metadata.get('rhx_gis')
except (QueryReturnedNotFoundException, KeyError) as err:
top_search_results = TopSearchResults(self._context, self.username)
similar_profiles = [profile.username for profile in top_search_results.get_profiles()]
if similar_profiles:
raise ProfileNotExistsException('Profile {} does not exist.\nThe most similar profile{}: {}.'
.format(self.username,
's are' if len(similar_profiles) > 1 else ' is',
', '.join(similar_profiles[0:5]))) from err
raise ProfileNotExistsException('Profile {} does not exist.'.format(self.username)) from err
def _metadata(self, *keys) -> Any: