Created
July 27, 2024 01:14
-
-
Save disposedtrolley/9e338f7792bb4bcf329e85aa65504214 to your computer and use it in GitHub Desktop.
Readwise Reader to Anybox converter
This file contains 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 | |
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