Skip to content

Instantly share code, notes, and snippets.

@thesamovar
Created June 12, 2025 16:04
Show Gist options
  • Save thesamovar/836a8a0359b7eeb33db25ffe14baf411 to your computer and use it in GitHub Desktop.
Save thesamovar/836a8a0359b7eeb33db25ffe14baf411 to your computer and use it in GitHub Desktop.
Create HTML file from Pocket CSV
from collections import defaultdict
import csv
with open('part_000001.csv', newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
rows = [row for row in reader]
rows_sorted = sorted(rows, key=lambda x: int(x['time_added']), reverse=True)
unread_rows = [row for row in rows_sorted if row['status'] == 'unread']
# Group unread_rows by tags
grouped = defaultdict(list)
for row in unread_rows:
tag = row['tags'].strip() if row['tags'].strip() else 'untagged'
grouped[tag].append(row)
html_content_grouped = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Unread Items Grouped by Tag</title>
</head>
<body>
<h1>Unread Items Grouped by Tag</h1>
"""
for tag, items in grouped.items():
html_content_grouped += f' <h2>{tag}</h2>\n <ul>\n'
for row in items:
title = row['title']
url = row['url']
html_content_grouped += f' <li><a href="{url}">{title}</a></li>\n'
html_content_grouped += ' </ul>\n'
html_content_grouped += """
</body>
</html>
"""
with open("unread_list_grouped.html", "w", encoding="utf-8") as f:
f.write(html_content_grouped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment