Created
May 22, 2013 13:15
-
-
Save edgarjcfn/5627455 to your computer and use it in GitHub Desktop.
Python script to convert Producteev exported files (.CSV) to Evernote Archived Notes (.ENEX)
This file contains hidden or 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/python | |
| # -*- coding: utf8 -*- | |
| import sys | |
| def producteev_to_evernote (csv_file, enex_file): | |
| # Convert Producteev .CSV file to Evernote .ENEX format | |
| # Based on Phat2Enex file from http://pastebin.com/jq8NRhsG | |
| # csv file must be in UTF-8 encoding | |
| import csv | |
| import time | |
| import string | |
| input_file = open(csv_file, "rb") | |
| of = open(enex_file, "wb") | |
| counter = 0 | |
| skipcounter = 0 | |
| of.write('<?xml version="1.0" encoding="UTF-8"?>\n') | |
| of.write('<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export2.dtd">\n') | |
| of.write('<en-export export-date="'+time.strftime('%Y%m%dT%H%M%SZ')+'" application="Evernote" version="Evernote Mac 5.0.7 (400993)">\n') | |
| rdr = csv.DictReader(input_file, dialect='excel', | |
| fieldnames=['title', 'workspace', 'status', 'priority', 'labels', 'deadline', 'creator', 'created_on', 'responsible', 'completed_on', 'no_subtasks', 'subtasks', 'no_notes', 'notes', 'updated_on', 'id_task']) | |
| for rec in rdr: | |
| try: | |
| counter = counter +1 | |
| if counter==1: | |
| continue | |
| of.write('<note>') | |
| of.write('<title>'+rec['title']+'</title>') | |
| of.write('<content>') | |
| of.write('<![CDATA[<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">\n\n') | |
| of.write('<en-note>') | |
| of.write('<div>') | |
| of.write(rec['notes']) | |
| of.write('</div>') | |
| of.write('</en-note>]]>\n') | |
| of.write('</content>') | |
| ctime=time.strftime('%Y%m%dT%H%M%SZ') | |
| mtime=time.strftime('%Y%m%dT%H%M%SZ') | |
| of.write('<created>'+ctime+'</created>') | |
| of.write('<updated>'+mtime+'</updated>') | |
| of.write('<note-attributes>') | |
| of.write('<source>mobile.android</source>') | |
| of.write('</note-attributes>') | |
| of.write('</note>\n') | |
| except: | |
| skipcounter = skipcounter + 1 | |
| print "error, skipping..." | |
| pass | |
| of.write('</en-export>\n') | |
| input_file.close() | |
| of.close () | |
| print 'Records processed'+str(counter)+' Records skipped:'+str(skipcounter) | |
| # end def producteev_to_evernote | |
| try: | |
| producteev_to_evernote(sys.argv[1], sys.argv[2]) | |
| except: | |
| print "Convert PhatNotes csv file to Evernote .enex format" | |
| print "Usage: phatcsv2enex.py csv_file enex_file" | |
| print "\nNote: csv file must be in UTF-8 encoding" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment