


# https://www.globalsino.com/ICs/


import html
import time

# Input and output file paths
txt_file_path = r'C:\0Python\file_log.txt'
output_html_path = r'C:\0Python\generated_bookmarks.html'

# Read and clean lines from the TXT file
with open(txt_file_path, 'r', encoding='utf-8') as f:
    lines = [line.strip() for line in f if line.strip()]

# Current timestamp for all bookmarks
timestamp = int(time.time())

# HTML Header
header = f'''<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
     It will be read and overwritten.
     DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
    <DT><H3 ADD_DATE="{timestamp}" LAST_MODIFIED="{timestamp}" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks bar</H3>
    <DL><p>
'''

# HTML Footer
footer = '''    </DL><p>
</DL><p>
'''

# Convert lines to bookmark entries
entries = ""
for line in lines:
    safe_line = html.escape(line)  # Escape special HTML characters
    entries += f'        <DT><A HREF="https://www.globalsino.com" ADD_DATE="{timestamp}">{safe_line}</A>\n'

# Write to output HTML file
with open(output_html_path, 'w', encoding='utf-8') as f:
    f.write(header + entries + footer)

print(f"✔️ Chrome bookmarks HTML created: {output_html_path}")
