09 November 2012

Geek: Dealing With .vnt Files

I switched this year from an iPhone to an Android phone, for a few reasons, which I might get into at some point in the future.  I use the Memo app on 'Droid to record notes; very often I use it to keep track of my weight before a hike, as well as the weight of my gear.  Getting data out of the app proved to be annoying.  I can export it to my computer through Dropbox, but it's in a .vnt format, that looks an awful lot like a vCard format, but I couldn't find any pre-built software capable of parsing it.  I was, however, able to come up with a quick workaround.

N.B.: this post assumes that you have a basic working knowledge of Linux, FreeBSD, or some other Unix or Unix-like system.  It assumes that you can install packages (vpim) on your system, and it also assumes that you know HOW to install packages (or compile software from distributed source code).  It also assumes that you have already have exported the Memo that you wrote on your Android phone into a .vnt format file.  It assumes that you are staring at that file, debating whether or not to just do a search and replace on those =0D=0A characters, and wondering why the Memo app couldn't just export a text file.

The .vnt file looks like this:
[doug@airship-pirate work]$ cat 2012-11-09.21.49.18.vnt
BEGIN:VNOTE
VERSION:1.1
BODY;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:Test=0D=0A=0D=0AMessage=0D=0AHere
DCREATED:20121109T214918
LAST-MODIFIED:20121109T214918
END:VNOTE
[doug@airship-pirate work]$ 
So, the content is in there, "Test Message Here", but it's a bit hard to work with.  You have a few options for translating this.  The most robust way is to use a vNote reader, but I have yet to find one, or have reason to write one.  So we'll use a vCard reader instead.  The package "vpim" provides a few utilities, including vcf-dump, which we'll exploit for our own nefarious purposes in just a moment.  First, though, we have to tweak that VNOTE into a VCARD.  If you don't do this step, vcf-dump gets all cranky.
[doug@airship-pirate work]$ sed -e 's/VNOTE/VCARD/' 2012-11-09.21.49.18.vnt > 2012-11-09.21.49.18.vcf
[doug@airship-pirate work]$ head -1 2012-11-09.21.49.18.vcf
BEGIN:VCARD
[doug@airship-pirate work]$ 
Easy enough.

Next, run it through vcf-dump:
[doug@airship-pirate work]$ vcf-dump 2012-11-09.21.49.18.vcf
..Begin="VCARD"
..Version="1.1"
..Body="Test\r\n\r\nMessage\r\nHere"
 ENCODING=[QUOTED-PRINTABLE]
 CHARSET=[UTF-8]
..Dcreated="20121109T214918"
..Last-modified="20121109T214918"
..End="VCARD"
Great.  vcf-dump handled translating that quoted-printable string, and presumably would handle other encodings as well (i.e. base64), without too much effort on our part.

Finally, the last step.  I'm going to grab that "Body" line, cut out the portion between the quotes, and then translate those CRLFs ("\r\n") into actual newlines. 
[doug@airship-pirate work]$ vcf-dump 2012-11-09.21.49.18.vcf | fgrep "Body=" | cut -f 2 -d '"' | sed -e 's/\\r\\n/\n/g'
Test

Message
Here
Voilà.

I hope that helps.  Please remember to back up any files prior to attempting to translate them, since one botched '>' can ruin your day.

No comments:

Post a Comment