Learning Python, I found Evernote's python script b64dec.py for converting notes described in an .ENEX file back to their native format.
I was unclear how it even worked at first. I could not find a "cat" command for example. (Line 27 in github listing)
# cat base64File | python b64dec.py myfile.ext
I concluded eventually you invoke it with :
<source ENEX file> | python b64dec.py <outputfile.desired_extension >
Is that correct?
I have tried sending a text only note to a .txt file, and an image only note to a .jpg file. They all end up zero length files.
Am I invoking this script correctly. Do I understand its purpose correctly (converts a note with an image back to an image etc.).
#!/usr/bin/env python
# Copyright 2013 Evernote Corporation. All rights reserved.
import base64
import sys
# Copy the base64 string from the ENEX file and put it into a file
# Pipe base64-encoded data to STDIN
data = sys.stdin.read()
# Decode data
try:
imgraw = base64.b64decode(data)
except TypeError, te:
print 'TypeError: ', te
raise SystemExit
# Write it to the file passed as a param
with file(sys.argv[1], 'wb') as outfile:
outfile.write(imgraw)
## Usage:
## (Change myfile.ext to the desired filename and correct extension)
# cat base64File | python b64dec.py myfile.ext
## or, if you base64 data is in the pasteboard on a Mac:
# pbpaste | python b64dec.py myfile.ext