diff --git a/Whatsapp_Chat_Exporter/__main__.py b/Whatsapp_Chat_Exporter/__main__.py index ceb79d5..c8cf0ed 100644 --- a/Whatsapp_Chat_Exporter/__main__.py +++ b/Whatsapp_Chat_Exporter/__main__.py @@ -67,6 +67,12 @@ def main(): default=None, help="Path to key file" ) + parser.add_option( + "-t", + "--template", + dest="template", + default=None, + help="Path to custom HTML template") (options, args) = parser.parse_args() if options.android and options.iphone: @@ -138,7 +144,7 @@ def main(): messages(db, data) media(db, data, options.media) vcard(db, data) - create_html(data, options.output) + create_html(data, options.output, options.template) if not os.path.isdir(f"{options.output}/{options.media}"): shutil.move(options.media, f"{options.output}/") diff --git a/Whatsapp_Chat_Exporter/extract.py b/Whatsapp_Chat_Exporter/extract.py index 9859aad..5096f38 100644 --- a/Whatsapp_Chat_Exporter/extract.py +++ b/Whatsapp_Chat_Exporter/extract.py @@ -294,12 +294,17 @@ def vcard(db, data): print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r") -def create_html(data, output_folder): - templateLoader = jinja2.FileSystemLoader(searchpath=os.path.dirname(__file__)) +def create_html(data, output_folder, template=None): + if template is None: + template_dir = os.path.dirname(__file__) + template_file = "whatsapp.html" + else: + template_dir = os.path.dirname(template) + template_file = os.path.basename(template) + templateLoader = jinja2.FileSystemLoader(searchpath=template_dir) templateEnv = jinja2.Environment(loader=templateLoader) templateEnv.globals.update(determine_day=determine_day) - TEMPLATE_FILE = "whatsapp.html" - template = templateEnv.get_template(TEMPLATE_FILE) + template = templateEnv.get_template(template_file) total_row_number = len(data) print(f"\nCreating HTML...(0/{total_row_number})", end="\r") diff --git a/Whatsapp_Chat_Exporter/extract_iphone.py b/Whatsapp_Chat_Exporter/extract_iphone.py index cdb96ae..2db090e 100644 --- a/Whatsapp_Chat_Exporter/extract_iphone.py +++ b/Whatsapp_Chat_Exporter/extract_iphone.py @@ -206,12 +206,17 @@ def vcard(db, data): print(f"Gathering vCards...({index + 1}/{total_row_number})", end="\r") -def create_html(data, output_folder): - templateLoader = jinja2.FileSystemLoader(searchpath=os.path.dirname(__file__)) +def create_html(data, output_folder, template=None): + if template is None: + template_dir = os.path.dirname(__file__) + template_file = "whatsapp.html" + else: + template_dir = os.path.dirname(template) + template_file = os.path.basename(template) + templateLoader = jinja2.FileSystemLoader(searchpath=template_dir) templateEnv = jinja2.Environment(loader=templateLoader) templateEnv.globals.update(determine_day=determine_day) - TEMPLATE_FILE = "whatsapp.html" - template = templateEnv.get_template(TEMPLATE_FILE) + template = templateEnv.get_template(template_file) total_row_number = len(data) print(f"\nCreating HTML...(0/{total_row_number})", end="\r")