Thursday, July 4, 2024

chrome json to html

https://www.mediafire.com/file/l9ofnpueyeo298s/chrome__convert.7z/file Here's the source code
import json import os from jinja2 import Template def convert_json_to_html(input_file, output_file): try: with open(input_file, 'r', encoding='utf-8') as file: json_data = json.load(file) bookmarks = [] for item in json_data: bookmark = { 'id': item['id'], 'title': item['title'], 'url': item['url'], 'lastVisitTimeLocal': item['lastVisitTimeLocal'], 'lastVisitTimeUTC': item['lastVisitTimeUTC'], 'typedCount': item['typedCount'], 'visitCount': item['visitCount'] } bookmarks.append(bookmark) template_content = """ Bookmarks

Bookmarks

{% for bookmark in bookmarks %}

{{ bookmark.title }}

{{ bookmark.url }}

Last Visit: {{ bookmark.lastVisitTimeLocal }} (UTC: {{ bookmark.lastVisitTimeUTC }})

Typed Count: {{ bookmark.typedCount }}, Visit Count: {{ bookmark.visitCount }}

{% endfor %} """ template = Template(template_content) rendered_html = template.render(bookmarks=bookmarks) with open(output_file, 'w', encoding='utf-8') as file: file.write(rendered_html) except FileNotFoundError: print(f"File '{input_file}' not found.") except Exception as e: print(f"Failed to convert JSON to HTML: {e}") # Prompt the user to enter the path to the local JSON file json_file_path = input("Enter the path to the local JSON file: ").strip() try: output_file = f"{os.path.splitext(os.path.basename(json_file_path))[0]}.html" convert_json_to_html(json_file_path, output_file) except FileNotFoundError: print(f"File '{json_file_path}' not found.") except Exception as e: print(f"Error: {e}")

No comments:

Post a Comment