Skip to content

Instantly share code, notes, and snippets.

@disposedtrolley
Created July 27, 2024 01:14
Show Gist options
  • Save disposedtrolley/9e338f7792bb4bcf329e85aa65504214 to your computer and use it in GitHub Desktop.
Save disposedtrolley/9e338f7792bb4bcf329e85aa65504214 to your computer and use it in GitHub Desktop.
Readwise Reader to Anybox converter
#!/usr/bin/env python
import csv
import json
import sys
import os
from datetime import datetime
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: readwise_to_anybox <path/to/export.csv>")
exit(1)
infile = sys.argv[1]
out = []
f = open(infile, "r")
reader = csv.DictReader(f)
for row in reader:
if row["Location"] == "feed":
continue
trimmed_date = row["Saved date"][:19]
date_added = datetime.strptime(trimmed_date, "%Y-%m-%d %H:%M:%S")
out.append({
"isStarred": row["Document tags"] != "",
"tags": [],
"folder": [],
"dateAdded": date_added.strftime("%Y-%m-%dT%H:%M:%SZ"),
"comment": "",
"url": row["URL"],
"title": row["Title"],
"description" : "",
"keyword" : "",
"article" : ""
})
outfile = os.path.join(os.path.dirname(infile), "anybox.json")
with open(outfile, "w") as f:
f.write(json.dumps(out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment