Turtl's output JSON is a bit annoying, so here's a basic script to transfer text and password notes (only) to a markdown directory.
It's very limited in features since I only built it for personal use.
Place your output JSON (called turtl-backup.json
) in the same folder, and create a folder called turtl
.
NB: it ignores boards, users, and creation dates, and only copies notes that are in text or password form
I would upload the python file but discourse doesn't seem to like me doing that, so here's the source code in plain text. Yes it's not as efficient as it can be but it only has to work once.
import json, os
OUTPUT = "turtl/"
if OUTPUT != "" and OUTPUT[-1] != "/":
OUTPUT += "/"
def createUnnamedFile(board="", num=0):
try:
f = open(OUTPUT + board + f"Untitled-{num}.md", "x")
f.close()
return "Untitled-%i" % num
except FileExistsError:
return createUnnamedFile(board, num + 1)
with open("turtl-backup.json") as f:
data = json.load(f)
boards = {}
for b in data["boards"]:
boards[b["id"]] = str(b["title"])
try:
os.mkdir(OUTPUT + b["title"])
except FileExistsError:
print("board directory already exists")
for n in data["notes"]:
outdir = ""
if n["board_id"] != None:
try:
outdir = boards[n["board_id"]] + "/"
except KeyError:
print("board not found")
print("board id:", n["board_id"])
if n["title"] == "":
name = createUnnamedFile(outdir) + ".md"
else:
name = n["title"].strip() + ".md"
outData = []
if n["type"] == "text":
outData = [n["text"]]
elif n["type"] == "password":
outData = [n["password"]]
#print(len(outData))
with open(f"{OUTPUT}{outdir}{name}", "w") as f:
f.writelines(outData)