Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #17 from t0xic-m/bugfix_un-encoding
Browse files Browse the repository at this point in the history
Bugfix username encoding
  • Loading branch information
Micha Birklbauer authored Jan 25, 2021
2 parents 81f715c + d03f90b commit e38592e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ instaview()
- html_string (str): json converted to html.
- status (int): Amount of encountered errors.
- error_log (str): Log of all encountered errors.
- **read_messages(filename = "messages.json", profile = "profile.json", reverse_conversations = False, profile_pic = None, default_avatar = None, download_all = False, hd = False, avatars_dict = {}, http_traceback = False):**
- **read_messages(filename = "messages.json", profile = "profile.json", reverse_conversations = False, profile_pic = None, default_avatar = None, download_all = False, hd = False, infer_usernames = False, avatars_dict = {}, http_traceback = False):**
Reads message information from json file and creates separate html files for each chat in new "chat" directory. Links to html pages are returned as concatenated html string together with a list of chat participants.
- **Args:**
- filename (str): Path to json with message information or path to folder containing messages. Default: "messages.json".
Expand All @@ -134,6 +134,7 @@ instaview()
- default_avatar (str): Path or link to default avatar. Default: None (uses instagram.com/instagram profile picture [\[1\]](#Disclaimer)).
- download_all (bool): If all media links should be downloaded locally. Warning: This might take a very long time! Default: False.
- hd (bool): If high definition versions of avatars should be used or not. Default: False.
- infer_usernames (bool): If usernames should be infered from thread information and avatars tried to be downloaded. Default: False (Default avatars for users).
- avatars_dict (dict): A dictionary containing usernames and corresponding paths/links to profile pictures. Argument "profile_pic" overwrites user's avatar even if specified in avatars_dict. Default: empty dict (will be populated by method itself).
- avatar_warnings (bool): Print warnings for getting avatars. Default: False (No warnings are printed).
- http_traceback (bool): Print the full traceback for http errors or not. Default: False (Traceback will not be printed).
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ instaview()
- html_string (str): json converted to html.
- status (int): Amount of encountered errors.
- error_log (str): Log of all encountered errors.
- **read_messages(filename = "messages.json", profile = "profile.json", reverse_conversations = False, profile_pic = None, default_avatar = None, download_all = False, hd = False, avatars_dict = {}, http_traceback = False):**
- **read_messages(filename = "messages.json", profile = "profile.json", reverse_conversations = False, profile_pic = None, default_avatar = None, download_all = False, hd = False, infer_usernames = False, avatars_dict = {}, http_traceback = False):**
Reads message information from json file and creates separate html files for each chat in new "chat" directory. Links to html pages are returned as concatenated html string together with a list of chat participants.
- **Args:**
- filename (str): Path to json with message information or path to folder containing messages. Default: "messages.json".
Expand All @@ -138,6 +138,7 @@ instaview()
- default_avatar (str): Path or link to default avatar. Default: None (uses instagram.com/instagram profile picture [\[1\]](#Disclaimer)).
- download_all (bool): If all media links should be downloaded locally. Warning: This might take a very long time! Default: False.
- hd (bool): If high definition versions of avatars should be used or not. Default: False.
- infer_usernames (bool): If usernames should be infered from thread information and avatars tried to be downloaded. Default: False (Default avatars for users).
- avatars_dict (dict): A dictionary containing usernames and corresponding paths/links to profile pictures. Argument "profile_pic" overwrites user's avatar even if specified in avatars_dict. Default: empty dict (will be populated by method itself).
- avatar_warnings (bool): Print warnings for getting avatars. Default: False (No warnings are printed).
- http_traceback (bool): Print the full traceback for http errors or not. Default: False (Traceback will not be printed).
Expand Down
11 changes: 8 additions & 3 deletions instaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def reverse_generate_messages_json(filename = "messages.json"):
# for args refer to README.md
# there are no input checks, incorrect inputs will lead to crashes!
# so be careful if you don't want things to go sideways
def read_messages(filename = "messages.json", profile = "profile.json", reverse_conversations = False, profile_pic = None, default_avatar = None, download_all = False, hd = False, avatars_dict = {}, avatar_warnings = False, http_traceback = False):
def read_messages(filename = "messages.json", profile = "profile.json", reverse_conversations = False, profile_pic = None, default_avatar = None, download_all = False, hd = False, infer_usernames = False, avatars_dict = {}, avatar_warnings = False, http_traceback = False):

GENERATED = False

Expand Down Expand Up @@ -995,7 +995,12 @@ def get_media(media_share_url, download_all = download_all):
participants_new.append(participant)
if participant not in avatars:
infered_participant_username = item["thread_path"].split("/")[-1].split("_")[0].split("-")[0]
avatars[participant] = str(get_avatar(infered_participant_username))
if infer_usernames:
avatars[participant] = str(get_avatar(infered_participant_username))
else:
file_name = "chat/icons/" + str(infered_participant_username) + ".jpg"
ur.urlretrieve(default_avatar, file_name)
avatars[participant] = "icons/" + str(infered_participant_username) + ".jpg"
else:
# this should probably throw an exception
participants_new = ["ERROR ", "reading participants!"]
Expand Down Expand Up @@ -1036,7 +1041,7 @@ def get_media(media_share_url, download_all = download_all):
html_chat_string = html_chat_string + "\t<img src=\"" + str(avatars[message["sender_name"]]) + "\" alt=\"" + str(message["sender_name"]).upper() + "\" class=\"right\" style=\"width:100%;\">\n"
elif message["sender_name"].encode("ISO-8859-1").decode("utf-8") == user_profile_name:
html_chat_string = html_chat_string + "<div class=\"container darker\">\n"
html_chat_string = html_chat_string + "\t<img src=\"" + str(avatars[message["sender_name"]]) + "\" alt=\"" + str(message["sender_name"]).upper() + "\" class=\"right\" style=\"width:100%;\">\n"
html_chat_string = html_chat_string + "\t<img src=\"" + str(avatars[user_profile_name]) + "\" alt=\"" + str(user_profile_name).upper() + "\" class=\"right\" style=\"width:100%;\">\n"
else:
if message["sender_name"] in avatars:
html_chat_string = html_chat_string + "<div class=\"container\">\n"
Expand Down

0 comments on commit e38592e

Please sign in to comment.