Paul Swartz ([info]z3p) wrote,
  • Music: Futurama

HOWTO: Syncing Tomboy with an iPod

I take all of my notes with Tomboy, a simple note-taking application for GNOME.  However, I'm not always at my computer when I want to look at my notes.  That's why I hacked together this little script, which converts Tomboy notes into iPod Notes.  It's listed below the cut



It assume that your iPod is mounted at /media/ipod, and it puts all the notes into a subdirectory called tomboy.

#!/usr/bin/env python



from xml.dom.minidom import parse



import os, os.path, sys







def fixTitle(title):



bad = '"'



for c in bad:



title = title.replace(bad, '')



return title







def getTextFromChildren(node):



return ''.join([getTextFrom(n) for n in node.childNodes])







def getTextFrom(node):



if node.nodeType == 3:



return node.data



elif node.nodeName == 'link:internal':



link = fixTitle(node.firstChild.data)



return '<a href="%s">%s</a>' % (link, link)



elif node.nodeName == 'italic':



return '/%s/' % getTextFromChildren(node)



elif node.nodeName == 'bold':



return '*%s*' % getTextFromChildren(node)



elif node.nodeName == 'underline':



return '_%s_' % getTextFromChildren(node)



elif node.nodeName == 'highlight':



return '[[[%s]]]' % getTextFromChildren(node)



else:



return getTextFromChildren(node)







def parseNote(f):



dom = parse(f)



de = dom.documentElement



assert de.nodeName == 'note'



title = fixTitle(de.getElementsByTagName('title')[0].firstChild.data)



texts = de.getElementsByTagName('text')[0].getElementsByTagName('note-content')[0].childNodes



text = ''.join([getTextFrom(node) for node in texts]).split('\n\n',1)[1]



return (title, text)







def splitNote(title,text):



parts = []



number = 0



while len(text) > 3900:



number = len(parts)



first = text[:3900]



lastSpace = first.rfind(' ')



newText = '%s\n<a href="%s%i">&gt;</a>' % (text[:lastSpace], title, number+1)



text = text[lastSpace:].lstrip()



parts.append(['%s%i' % (title, number), newText])



parts.append(['%s%i' % (title, number+1), text])



parts[0][0] = title



return parts







tomboyDir = os.path.expanduser('~/.tomboy')



ipodDir = '/media/ipod/Notes/'







if not os.path.exists(ipodDir):



sys.exit(1)







os.system('rm -rf %s/tomboy' % ipodDir)



os.mkdir(os.path.join(ipodDir, 'tomboy'))







files = os.listdir(tomboyDir)



for f in files:



if not f.endswith('.note'):



continue



title, text = parseNote(file(os.path.join(tomboyDir, f)))



parts = splitNote(title, text)



for name, value in parts:



#print 'Writing %s...' % name



fullPath = os.path.join(ipodDir,'tomboy',name)



file(fullPath, 'w').write(value.encode('latin1', 'xmlcharrefreplace'))



Tags: ipod, sync, tomboy

  • Post a new comment

    Error

    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    Your IP address will be recorded 

  • 1 comments

Anonymous

October 28 2007, 23:06:41 UTC 4 years ago

LINKS

Hello, nice site look this: End ^) See you
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…