Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
A script to export your notes from the [Vesper](http://vesperapp.co) iOS app to text files.
Exported notes can include markdown formatting with the `--markdown` switch.

## Known Issues

- This was developed against Vesper 1.003. The data model has changed in newer versions and the script is incompatible with version 2+.
- Supporting new Vesper data model versions is a moving target. The syncing feature added in 2.0 removes the need for exporting for backup. That said, patches are welcome.

## Usage

- Using a tool like [PhoneView](https://www.ecamm.com/mac/phoneview/):
Expand Down
38 changes: 30 additions & 8 deletions vesper-export.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,52 @@

def exportNotes(cursor, destDir, markdownify=False):
print "Exporting to '%s':" % destDir
query = "SELECT uniqueId,text,archived,attachmentUniqueID,tags from notes;"
for record in cursor.execute(query):
id = record[0]

rowsNotes = cursor.execute("SELECT uniqueId,text,archived,thumbnailID,creationDate,textModificationDate from notes;").fetchall()
rowsTags = cursor.execute("SELECT tagID,noteID from tagsNotesLookup;").fetchall()

# Parse tags into a dictionary[noteID:[tagNames]]
tags = {}
for tag in rowsTags:
tagName = tag[0].encode("utf-8")
noteID = str(tag[1])

itemTags = []
if set([noteID]).issubset(tags):
itemTags = tags[noteID]

itemTags.append(tagName)
tags[noteID] = itemTags

for record in rowsNotes:
id = str(record[0])
text = record[1].encode("utf-8") if record[1] else None
archived = bool(record[2])
imageId = record[3].encode("utf-8") if record[3] else None
tags = record[4].encode("utf-8") if record[4] else None
dateCreated = record[4]
dateModified = record[5] if record[5] != None else dateCreated
recordTags = tags[id] if set([id]).issubset(tags) else None

ext = ".md" if markdownify else ".txt"
title = text.splitlines()[0].strip() + ext
title = title[:255].replace("/", "-")
path = os.path.join(destDir,title)
file = open(path, "w")

if imageId:
if markdownify:
file.write("![Header Image](images/%s)\n\n" % imageId)
file.write("![Header Image](images/{0})\n\n".format(imageId))
else:
file.write("Image: images/%s\n\n", imageId)
file.write("Image: images/{0}\n\n".format(imageId))
if markdownify:
file.write("# ")
file.write(text)
if tags:
file.write("\nTags: %s" % tags)
if recordTags:
file.write("\nTags: {0}".format( ", ".join(recordTags) ))
file.close()

os.utime(path, (dateCreated, dateModified))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


print " Exported '%s'" % title
print "Done"
pass
Expand Down