#!/usr/bin/env python3 # INSTAGRAM JSON VIEWER # 2020 (c) Micha Johannes Birklbauer # https://github.com/t0xic-m/ # micha.birklbauer@gmail.com from datetime import datetime as dt import urllib.request as ur import traceback as tb import time import json import os # template html # largely taken and adapted from w3schools.com # -> https://www.w3schools.com/howto/howto_css_fixed_sidebar.asp # -> https://www.w3schools.com/howto/howto_css_chat.asp html_template = \ """
Report created with Micha Birklbauer's Instagram JSON Viewer.
""" # reading profile information and converting it to html string # default filenames and arguments should be fine for all functions if script is in the right directory def read_profile(filename = "profile.json"): # error controls and logging status = 0 errors = [] # html template html_string = "\n\t\t\n\t\t
\n\t\tMedia Owner: " + str(message["media_owner"]) + "
\n"
content = content + "\t\tMedia Caption: " + str(message["media_share_caption"]) + "
\n"
if "text" in message:
content = content + "\t\t
Text: " + str(message["text"]) + "\n"
html_chat_string = html_chat_string + content + "\t
\n\t\tVoice Message: Media unavailable.
\n"
else:
content = "\t
\n\t\tVoice Message:\n\t\t
\n\t\t\t\n\t\t
\n"
if "text" in message:
content = content + "\t\t
Text: " + str(message["text"]) + "\n"
html_chat_string = html_chat_string + content + "\t
\n\t\tVideo:\n\t\t
\n\t\t\t\n\t\t
\n"
elif message["media"].split("?")[0].split(".")[-1] == "m4a":
content = "\t
\n\t\tVoice Message:\n\t\t
\n\t\t\t\n\t\t
\n"
else:
content = "\t
\n\t\tImage:\n\t\t
\n\t\t\t\n\t\t
\n"
if "text" in message:
content = content + "\t\t
Text: " + str(message["text"]) + "\n"
html_chat_string = html_chat_string + content + "\t
\n\t\tStory Share: " + str(message["story_share"]) + "
\n"
if "text" in message:
content = content + "\t\t
Text: " + str(message["text"]) + "\n"
html_chat_string = html_chat_string + content + "\t
\n\t\tLink: " + str(message["link"]) + "
\n"
if "text" in message:
content = content + "\t\t
Text: " + str(message["text"]) + "\n"
html_chat_string = html_chat_string + content + "\t
\n\t\tText: " + str(message["text"]) + "\n" else: content = "\t
\n" html_chat_string = html_chat_string + content + "\t
\n" elif "sender_name" in message: if "type" in message: if message["type"] == "Generic": content = "\t\n"
if "photos" in message:
for photo_item in message["photos"]:
content = content + "\t\tImage:\n\t\t
\n\t\t\t\n\t\t
\n"
if "content" in message:
content = content + "\t\tContent: " + str(message["content"]).encode("ISO-8859-1").decode("utf-8") + "\n"
if "photos" not in message and "content" not in message:
content = "\t\tContent: Content not available!\n"
html_chat_string = html_chat_string + content + "\t
\n" if "share" in message: share = message["share"] content = content + "\t\t
\n\t\tContent (unknown type): Content not available!\n" html_chat_string = html_chat_string + content + "\t
\n" else: print("INFO - No content type detected.") if "content" in message: content = "\t\n\t\tContent (undetected type): " + str(message["content"]).encode("ISO-8859-1").decode("utf-8") + "\n" html_chat_string = html_chat_string + content + "\t
\n" else: content = "\t\n\t\tContent (undetected type): Content not available!\n" html_chat_string = html_chat_string + content + "\t
\n" else: # this should probably throw an exception pass if "sender" in message: if message["sender"] == user_username: if "created_at" in message: html_chat_string = html_chat_string + "\t" + str(message["created_at"]) + "\n