Last active
April 4, 2025 07:34
-
-
Save svandragt/b8901a1643332295339b9a9b987b5389 to your computer and use it in GitHub Desktop.
Convert (Instapaper) CSV to Netscape Bookmark File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Convert CSV to Netscape Bookmark File | |
Works for files exported by Instapaper. | |
author: Sander van Dragt <[email protected]> | |
version: 2019-10-23.01 | |
""" | |
import csv | |
from sys import argv | |
def bookmark_footer(): | |
print("</DL><p>") | |
def bookmark_header(): | |
print( | |
""" | |
<!DOCTYPE NETSCAPE-Bookmark-file-1> | |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> | |
<!-- This is an automatically generated file. | |
It will be read and overwritten. | |
Do Not Edit! --> | |
<TITLE>Bookmarks</TITLE> | |
<H1>Bookmarks</H1> | |
<DL><p> | |
""" | |
) | |
def bookmark_row(row): | |
print('<DT><A HREF="{URL}" ADD_DATE="{Timestamp}">{Title}</A>'.format(**row)) | |
def main(): | |
try: | |
with open(argv[1], mode="r") as csv_file: | |
csv_reader = csv.DictReader(csv_file) | |
line_count = 0 | |
bookmark_header() | |
for row in csv_reader: | |
line_count += 1 | |
if line_count == 1: | |
continue | |
bookmark_row(row) | |
bookmark_footer() | |
except IndexError: | |
print("Usage: csv2bm.py <bookmarks.csv>") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3 csv2bm.py bookmarks.csv > bookmarks.html