import csv
from datetime import datetime
# Get the current date and time
current_datetime = date.now().strftime("%Y-%m-%d")
current_datetime = time.now().strftime("%H:%M:%S")
# Read the CSV file
with open('links.txt', 'r', newline='', encoding='utf-8') as csvfile:
# Read CSV data assuming tab-separated values
csvreader = csv.reader(csvfile, delimiter='\t')
# Prepare HTML content
html_content = f"""
My Youtube Follows
My Youtube Follows {current_date} {current_time}
This list was generated using the excellent
YouTube Exporter for chrome -
and a bit of Python (rename .txt to .py) (works with Python Version 3.11.9
# Add proper url for source code
"""
# Add each link to the HTML content
for row in csvreader:
# If the row is empty, add a horizontal rule
if not row:
html_content += '
\n'
else:
# Ensure there are two columns (title and URL)
if len(row) >= 2:
title, url = row
html_content += f' - {title} - {url}
\n'
# Close the list and HTML tags
html_content += """
"""
# Write the HTML content to an HTML file
with open('index.html', 'w', encoding='utf-8') as htmlfile:
htmlfile.write(html_content)
print("HTML file 'index.html' generated successfully.")